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 +*/ 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..08ecc831 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); +// }); 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..a0705996 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,7 +19,19 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here + 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 +55,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 +}); 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`