From 64610044a26a60aec33aebe1f990c2856b6f6d28 Mon Sep 17 00:00:00 2001 From: bita2019 <58438858+bita2019@users.noreply.github.com> Date: Mon, 24 Jan 2022 10:21:25 +0000 Subject: [PATCH 1/6] 1 --- 1-exercises/A-accessing-values/exercise1.js | 8 ++++---- 1-exercises/A-accessing-values/exercise2.js | 6 +++--- 1-exercises/A-accessing-values/exercise3.js | 10 +++++++++- 1-exercises/B-setting-values/exercise1.js | 9 +++++++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..dcf5a5ce 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -8,7 +8,7 @@ let dog = { breed: "Dalmatian", name: "Spot", isHungry: true, - happiness: 6 + happiness: 6, }; /* @@ -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}`); @@ -25,4 +25,4 @@ console.log(`${dogName} is a ${dogBreed}`); Spot is a Dalmatian -*/ \ No newline at end of file +*/ diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index 5b523ace..02189d2b 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -7,7 +7,7 @@ let capitalCities = { UnitedKingdom: "London", China: "Beijing", - Peru: "Lima" + Peru: "Lima", }; /* @@ -17,7 +17,7 @@ let capitalCities = { */ let myCountry = "UnitedKingdom"; -let myCapitalCity; // complete the code +let myCapitalCity = capitalCities[myCountry]; // complete the code console.log(myCapitalCity); @@ -25,4 +25,4 @@ console.log(myCapitalCity); London -*/ \ No newline at end of file +*/ diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 2e160dd5..20c087c2 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,12 +21,20 @@ let basketballTeam = { */ // write code here +let b = basketballTeam.topPlayers; +b.sort(); +b.forEach((b) => { + console.log(b); +}); +// let topPlayers = basketballTeam.topPlayers; +// topPlayers.sort(); +// topPlayers.map((player) => console.log(player)); /* EXPECTED RESULT Dennis Rodman Michael Jordan Scottie Pippen -*/ \ No newline at end of file +*/ diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..21304f8d 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -10,7 +10,7 @@ let capitalCities = { }, China: { name: "Beijing", - } + }, }; /* @@ -23,6 +23,11 @@ let capitalCities = { */ // write code here +capitalCities.UnitedKingdom.population = 8980000; +capitalCities.China.population = 21500000; +capitalCities.Peru = {}; +capitalCities.Peru.name = "Lima"; +capitalCities.Peru.population = 9750000; console.log(capitalCities); @@ -34,4 +39,4 @@ console.log(capitalCities); Peru: { name: "Lima", population: 9750000 } } -*/ \ No newline at end of file +*/ From 06bad1cb096634d3867fd3063a2cb01c7e11b844 Mon Sep 17 00:00:00 2001 From: bita2019 <58438858+bita2019@users.noreply.github.com> Date: Tue, 25 Jan 2022 15:29:32 +0000 Subject: [PATCH 2/6] 2 --- .../C-undefined-properties/exercise.js | 10 ++--- 1-exercises/D-object-methods/exercise.js | 9 +++-- 2-mandatory/1-recipes.js | 39 ++++++++++++++++++- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..deab3ce5 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -14,15 +14,15 @@ let car = { yearsOld: 8, }; -console.log(car["colour"]); +console.log(car["colour"]); // we did,t define color in car object. // Example 2 function sayHelloToUser(user) { - console.log(`Hello ${user.firstName}`); + console.log(`Hello ${user.firstName}`); // we don't have .firstname property for user , we have .name . } let user = { - name: "Mira" + name: "Mira", }; sayHelloToUser(user); @@ -30,8 +30,8 @@ sayHelloToUser(user); // Example 3 let myPet = { animal: "Cat", - getName: function() { - "My pet's name is Fluffy"; + getName: function () { + "My pet's name is Fluffy"; // Function defination isn't correct , } missing. }, }; diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..bc02b8bf 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 -} + name: "Jack", + getName: function (name) { + console.log("Student name " + name); + }, // write code here +}; student.getName("Daniel"); @@ -17,4 +20,4 @@ student.getName("Daniel"); Student name: Daniel -*/ \ No newline at end of file +*/ diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..cc138a29 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -21,5 +21,42 @@ You should write and log at least 5 recipes */ +let recipe1 = { + title: "Mole", + servings: 2, + ingredients: ["Cinnamon", "Cumin", "Cocoa"], +}; -// write code here \ No newline at end of file +let recipe2 = { + title: "Mashed Potato", + servings: 3, + ingredients: ["potato", "water"], +}; + +let recipe3 = { + title: "Brownie", + servings: 4, + ingredients: ["flour", "cocoa", "milk", "suger", "butter"], +}; + +let recipe4 = { + title: "Kale salad", + servings: 5, + ingredients: ["kale", "lettuce"], +}; + +let recipe5 = { + title: "energy booster", + servings: 3, + ingredients: ["ginger", "orange", "lime"], +}; +console.log(recipe1.title); +console.log("Serving :", recipe1.servings); +console.log("Ingredients :", recipe1.ingredients); +// write code here +// let b = basketballTeam.topPlayers; +// b.sort(); + +// b.forEach((b) => { +// console.log(b); +// }); From 2394085e5576d20383e076772985713bf7e7b330 Mon Sep 17 00:00:00 2001 From: bita2019 <58438858+bita2019@users.noreply.github.com> Date: Thu, 27 Jan 2022 14:25:26 +0000 Subject: [PATCH 3/6] 3 --- 2-mandatory/1-recipes.js | 2 +- 2-mandatory/2-currency-code-lookup.js | 8 +++-- 2-mandatory/3-shopping-list.js | 45 ++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index cc138a29..08ecc831 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -52,7 +52,7 @@ let recipe5 = { }; console.log(recipe1.title); console.log("Serving :", recipe1.servings); -console.log("Ingredients :", recipe1.ingredients); +console.log("Ingredients:", recipe1.ingredients); // write code here // let b = basketballTeam.topPlayers; // b.sort(); diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..75c81e96 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,7 +18,11 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here + let countryObj = {}; + for (let i = 0; i < countryCurrencyCodes.length; i++) { + countryObj[countryCurrencyCodes[i][0]] = countryCurrencyCodes[i][1]; + } + return countryObj; } /* ======= TESTS - DO NOT MODIFY ===== @@ -34,4 +38,4 @@ test("creates country currency code lookup", () => { NG: "NGN", MX: "MXN", }); -}); \ No newline at end of file +}); diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..22e34e8a 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -18,8 +18,38 @@ let pantry = { cupboardContents: ["salt", "tinned tomatoes", "oregano"], }; +// function createShoppingList(recipe) { +// for (i in recipe.ingredients) { +// if (!pantry.includes) recipe.items = i; +// // write code here +// } +// return recipe; +// } + function createShoppingList(recipe) { - // write code here + // allIngredients using .flat() + // const allIngredients = Object.values(pantry).flat(); + + // allIngredients using loops + // const allIngredients = []; + // Object.values(pantry).forEach((arrayOfValues) => { + // arrayOfValues.forEach((value) => allIngredients.push(value)); + // }); + + // allIngredients using the ... (spread) operator (my preferred way) + const allIngredients = [...pantry.fridgeContents, ...pantry.cupboardContents]; + + const missingItems = recipe.ingredients.filter((ingredient) => { + if (allIngredients.includes(ingredient)) { + return false; + } + return true; + }); + const objectToReturn = { + name: recipe.name, + items: missingItems, + }; + return objectToReturn; } /* ======= TESTS - DO NOT MODIFY ===== @@ -43,11 +73,18 @@ test("createShoppingList works for pancakes recipe", () => { test("createShoppingList works for margherita pizza recipe", () => { let recipe2 = { name: "margherita pizza", - ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella"], + ingredients: [ + "flour", + "salt", + "yeast", + "tinned tomatoes", + "oregano", + "mozarella", + ], }; expect(createShoppingList(recipe2)).toEqual({ name: "margherita pizza", - items: ["flour", "yeast", "mozarella"] + items: ["flour", "yeast", "mozarella"], }); -}); \ No newline at end of file +}); From a1eafc316de8e8e63ae6805288cc61b7bcd41192 Mon Sep 17 00:00:00 2001 From: bita2019 <58438858+bita2019@users.noreply.github.com> Date: Thu, 27 Jan 2022 16:17:57 +0000 Subject: [PATCH 4/6] Update 3-shopping-list.js --- 2-mandatory/3-shopping-list.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index 22e34e8a..b6bc9013 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,23 +20,13 @@ let pantry = { // function createShoppingList(recipe) { // for (i in recipe.ingredients) { -// if (!pantry.includes) recipe.items = i; +// if (!pantry.includes(i)) recipe.items = i; // // write code here // } // return recipe; // } function createShoppingList(recipe) { - // allIngredients using .flat() - // const allIngredients = Object.values(pantry).flat(); - - // allIngredients using loops - // const allIngredients = []; - // Object.values(pantry).forEach((arrayOfValues) => { - // arrayOfValues.forEach((value) => allIngredients.push(value)); - // }); - - // allIngredients using the ... (spread) operator (my preferred way) const allIngredients = [...pantry.fridgeContents, ...pantry.cupboardContents]; const missingItems = recipe.ingredients.filter((ingredient) => { From f7e656070ff11e1012f671b422e5d7e37a477cc1 Mon Sep 17 00:00:00 2001 From: bita2019 <58438858+bita2019@users.noreply.github.com> Date: Thu, 27 Jan 2022 20:51:28 +0000 Subject: [PATCH 5/6] Update 4-restaurant.js --- 2-mandatory/4-restaurant.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..fb8ac29c 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,9 +20,22 @@ const MENU = { }; let cashRegister = { - // write code here -} - + orderBurger: function (balance) { + let newBalance = balance; + if (balance >= MENU.burger) { + newBalance = balance - MENU.burger; + } + return newBalance; + }, + + orderFalafel: function (balance) { + let newBalance = balance; + if (balance >= MENU.falafel) { + newBalance = balance - MENU.falafel; + } + return newBalance; + }, +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` - To run all exercises/tests in the mandatory folder, run `npm test` From 1c8f175dd1526664e6cde2d883699c2498141a96 Mon Sep 17 00:00:00 2001 From: bita2019 <58438858+bita2019@users.noreply.github.com> Date: Thu, 27 Jan 2022 23:20:06 +0000 Subject: [PATCH 6/6] Update 3-shopping-list.js --- 2-mandatory/3-shopping-list.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index b6bc9013..a0705996 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -18,14 +18,6 @@ let pantry = { cupboardContents: ["salt", "tinned tomatoes", "oregano"], }; -// function createShoppingList(recipe) { -// for (i in recipe.ingredients) { -// if (!pantry.includes(i)) recipe.items = i; -// // write code here -// } -// return recipe; -// } - function createShoppingList(recipe) { const allIngredients = [...pantry.fridgeContents, ...pantry.cupboardContents];