diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..e3dfa76e 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -5,10 +5,10 @@ */ let dog = { - breed: "Dalmatian", - name: "Spot", - isHungry: true, - happiness: 6 + breed: "Dalmatian", //string + name: "Spot", //string + isHungry: true, //boolean + happiness: 6 //number }; /* @@ -16,8 +16,8 @@ let dog = { Log the name and breed of this dog using dot notation. */ -let dogName; // complete the code -let dogBreed; // complete the code +let dogName = dog.name; // complete the code +let dogBreed = dog.breed; // complete the code console.log(`${dogName} is a ${dogBreed}`); diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index 5b523ace..a18919e5 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -17,7 +17,7 @@ let capitalCities = { */ let myCountry = "UnitedKingdom"; -let myCapitalCity; // complete the code +let myCapitalCity = capitalCities["UnitedKingdom"]; // complete the code console.log(myCapitalCity); diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 2e160dd5..7fc74c9b 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,6 +21,13 @@ let basketballTeam = { */ // write code here +names = basketballTeam.topPlayers.sort() + +console.log(names.join('\n')); + +// names.forEach((player) => { +// console.log(player); +// }); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..4bf55a75 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -23,6 +23,9 @@ let capitalCities = { */ // write code here +capitalCities.UnitedKingdom.population = 8980000, +capitalCities.China.population = 21500000, +capitalCities.Peru = {name: "Lima", population: 9750000} console.log(capitalCities); diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..bb9a168d 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -16,6 +16,7 @@ let student = { */ // write code here +student["attendance"] = 90 /* - Write an "if" statement that changes the value of hasPassed to true @@ -26,6 +27,9 @@ let student = { */ // write code here +if (student["attendance"] >= 90 && student.examScore > 60) { + student.hasPassed = true +} console.log(student); diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..f79e95fb 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -13,8 +13,9 @@ let car = { brand: "Ford", yearsOld: 8, }; +// car.colour = "black", we need to define colour here. -console.log(car["colour"]); +console.log(car["colour"]); //we don't have a property called colour in the object so we get undefined. // Example 2 function sayHelloToUser(user) { @@ -22,7 +23,8 @@ function sayHelloToUser(user) { } let user = { - name: "Mira" + name: "Mira" + //firstName property does not exist }; sayHelloToUser(user); @@ -30,8 +32,9 @@ sayHelloToUser(user); // Example 3 let myPet = { animal: "Cat", - getName: function() { - "My pet's name is Fluffy"; + getName: function(name) { + + "My pet's name is Fluffy"; // we need to use the return key word statement }, }; diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..6346be91 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,9 +9,13 @@ let student = { // write code here + getName: function(name){ + +return `Student name: ${name} ` + } } -student.getName("Daniel"); +console.log(student.getName("Daniel")); /* EXPECTED RESULT diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..42b51a3f 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,51 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let favoriteRecipes = { + Title: "Chicken biryani", + Serves: 2, + Ingredients: ["chicken", "rice", "biryani masala"] + } + + + // Title: "spaghetti bolognese", + // Serves: 2, + // Ingredients: ["spaghetti", "olive oil", "onions"] + // }, + + // recipe5: { + // Title: "Chocalate cookies", + // Serves: 4, + // Ingredients: ["sugar", "butter", "flour", "eggs"] + // } + + + +console.log(favoriteRecipes.Title); +console.log(`Serves: ${favoriteRecipes.Serves}`); +console.log(`Ingredients: ${favoriteRecipes.Ingredients}`); + +// console.log(favoriteRecipes.recipe2.Title); +// console.log(`Serves: ${favoriteRecipes.recipe2.Serves}`); +// console.log(`Ingredients: ${favoriteRecipes.recipe2.Ingredients}`); + +// console.log(favoriteRecipes.recipe3.Title); +// console.log(`Serves: ${favoriteRecipes.recipe3.Serves}`); +// console.log(`Ingredients: ${favoriteRecipes.recipe3.Ingredients}`); + +// console.log(favoriteRecipes.recipe4.Title); +// console.log(`Serves: ${favoriteRecipes.recipe4.Serves}`); +// console.log(`Ingredients: ${favoriteRecipes.recipe4.Ingredients}`); + +// console.log(favoriteRecipes.recipe5.Title); +// console.log(`Serves: ${favoriteRecipes.recipe5.Serves}`); +// console.log(`Ingredients: ${favoriteRecipes.recipe5.Ingredients}`); + +// console.log(favoriteRecipes.title); +// console.log(`Serves: ${favoriteRecipes.serves}`); +// console.log("Ingredients:") +// favoriteRecipes.Ingredients.forEach((ingredient) => { +// console.log(ingredient); +// }); \ No newline at end of file diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..4680dd86 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,11 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + let counCurrency = {}; + countryCurrencyCodes.forEach(currency => { + counCurrency[currency[0]] = currency[1] + }); + return counCurrency } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..a683afe1 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,9 +19,16 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here -} - + let missingItems = recipe.ingredients.filter((item)=> { + + return !pantry.fridgeContents.includes(item) && !pantry.cupboardContents.includes(item) + + }); + return { + name : recipe.name, + items : missingItems, +}; +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js` - To run all exercises/tests in the mandatory folder, run `npm test` diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..d9ac69a2 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,7 +20,18 @@ const MENU = { }; let cashRegister = { - // write code here + orderBurger: function(balance){ + if(balance >= MENU.burger){ + return MENU.burger - balance + } + return balance; +}, + orderFalafel: function(balance){ + if(balance >= MENU.falafel){ + return MENU.falafel - balance + } + return balance + } } /* ======= TESTS - DO NOT MODIFY =====