diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..605b7fcb 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -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..c7c8e188 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[myCountry]; // 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..58b77980 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,7 +21,10 @@ let basketballTeam = { */ // write code here - +basketballTeam.topPlayers.sort(); +for (element of basketballTeam.topPlayers) { + console.log(element); +} /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..1d55781b 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -20,10 +20,16 @@ let capitalCities = { - Add the country "Peru" to capitalCities object. - Add a name of "Lima" to Peru's capital city. - Add a population of 9750000 to Peru's capital city. -*/ +*/ -// write code here +// write code here +capitalCities.UnitedKingdom.population = 8980000; +capitalCities.China.population = 21500000; +capitalCities["Peru"] = { + name:"Lima", + population: 9750000 +} console.log(capitalCities); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..18b66aba 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 @@ -25,7 +26,12 @@ let student = { - Use bracket notation to change the value of hasPassed */ +// const result2 = 10 > 100 ? 'yes' : 'no'; +// console.log(result2); // 👉️ 'no' + // write code here +let result = student.Attendance >= 90 && student.examScore > 60 ? student["hasPassed"] = true : student["hasPassed"] = false; +console.log(result); console.log(student); diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..231e4a26 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -14,7 +14,8 @@ let car = { yearsOld: 8, }; -console.log(car["colour"]); +console.log(car["colour"]); +//colour is not assigned to the car object // Example 2 function sayHelloToUser(user) { @@ -26,6 +27,7 @@ let user = { }; sayHelloToUser(user); +// user's first name is not defined // Example 3 let myPet = { @@ -36,3 +38,4 @@ let myPet = { }; console.log(myPet.getName()); +// The function has no return value diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..d61d2ce2 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -8,8 +8,11 @@ */ let student = { - // write code here + getName : function(name) { + return `Student name: ${name}` + }// write code here } +console.log(student.getName("Daniel")); student.getName("Daniel"); diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..bf328830 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,62 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here +let Recipe1 = { + Title: "Waina", + Serves: 2, + Ingredients: [ + "rice", + "water", + "yeast", + "miyan taushe", + "meat", + "oil" + ], +}; +let Recipe2 = { + Title: "Pounded Yam", + Serves: 1, + Ingredients: [ + "Yam or Yam flour", + "water", + "Egusi soup" + ], +}; +let Recipe3 = { + Title: "Coated Yam", + Serves: 1, + Ingredients: [ + "Yam", + "Eggs", + "oil", + "salt", + ], +}; +let Recipe4 = { + Title: "Peppered Fish", + Serves: 1, + Ingredients: ["Fish", "chilli pepper", "oil", "vegetables", "spices"], +}; +let Recipe5 = { + Title: "Puff Puff", + Serves: 2, + Ingredients: [ + "whole flour", + "milk", + "sugar", + "water", + "oil" + ], +}; + +function favoriteRecipe(obj) { + for ([key, value] of Object.entries(obj)) { + console.log(`${key}: ${value}`); + } +} +favoriteRecipe(Recipe1); +favoriteRecipe(Recipe2); +favoriteRecipe(Recipe3); +favoriteRecipe(Recipe4); +favoriteRecipe(Recipe5); diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..ebc5f566 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -10,6 +10,8 @@ Hint: you'll need to use bracket notation to add new key/value pairs to the object */ + + const COUNTRY_CURRENCY_CODES = [ ["GB", "GBP"], ["DE", "EUR"], @@ -19,6 +21,15 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + let newObject = {}; + for (element of countryCurrencyCodes) { + let country = element[0]; + let currency = element[1]; + newObject[country] = currency; + + } + + return newObject; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..1efa328c 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,6 +20,17 @@ let pantry = { function createShoppingList(recipe) { // write code here + let shoppingList = {}; + shoppingList.name = recipe.name; + shoppingList.items = []; + recipe.ingredients.map((item) => { + if ( + !pantry.fridgeContents.includes(item) && + !pantry.cupboardContents.includes(item) + ) + shoppingList.items.push(item); + }); + return shoppingList; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..ed7dea27 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,7 +21,21 @@ const MENU = { let cashRegister = { // write code here -} + orderBurger: function (balance) { + if (balance >= MENU.burger) { + return balance - MENU.burger; + } else { + return balance; + } + }, + orderFalafel: function (balance) { + if (balance >= MENU.falafel) { + return balance - MENU.falafel; + } else { + return balance; + } + }, +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`