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..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..ae8cb2f9 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 (let i = 0; i < basketballTeam.topPlayers.length; i++) { + console.log(basketballTeam.topPlayers[i]); +} /* EXPECTED RESULT @@ -29,4 +32,4 @@ let basketballTeam = { 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..a83171bc 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -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); diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..e4e86470 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -15,7 +15,7 @@ let student = { - Set the value of attendance to 90 */ -// write code here +student["attendance"] = 90; /* - Write an "if" statement that changes the value of hasPassed to true @@ -26,7 +26,9 @@ let student = { */ // write code here - +if (student.attendance >= 90 && student.examScore > 60) { + student["hasPassed"] = true; +} console.log(student); /* EXPECTED RESULT diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..ca13e6a4 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -14,7 +14,7 @@ let car = { yearsOld: 8, }; -console.log(car["colour"]); +console.log(car["colour"]); // There is no color property! // Example 2 function sayHelloToUser(user) { @@ -22,17 +22,17 @@ function sayHelloToUser(user) { } let user = { - name: "Mira" + name: "Mira", }; -sayHelloToUser(user); +sayHelloToUser(user); // There is no user firstName property. // Example 3 let myPet = { animal: "Cat", - getName: function() { + getName: function () { "My pet's name is Fluffy"; }, }; -console.log(myPet.getName()); +console.log(myPet.getName()); // There is no return function. diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..0d289fd7 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,6 +9,7 @@ let student = { // write code here + getName : (name) => console.log(`Student name: ${name}`) } student.getName("Daniel"); diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..7c8637c1 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,68 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let recipes = { + recipe1: { + title: "Pasta", + servings: 6, + ingredients: ["Pasta", "ketchub", "salt"], + }, + recipe2: { + title: "Pizza", + servings: 4, + ingredients: ["mince", "tomato", "mushroom", "chese", "onion"], + }, + recipe3: { + title: "manti", + serving: 4, + ingredients: [" dough", "minced meat", "tomato sauce", "yogurt"], + }, + recipe4: { + title: "icli kofte", + serving: 8, + ingredients: ["fine wheat", "minced-meat", "vegetable oil", "spices"], + }, + recipe5: { + title: "rice", + servings: 5, + ingredients: ["rice", "butter", "salt", "hot water"], + }, +}; +console.log("-------------Recipe 1 --------------------"); +console.log(recipes.recipe1.title); +console.log("Servings: " + recipes.recipe1.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe1.ingredients.length;i++){ + + console.log(recipes.recipe1.ingredients[i]); +} +console.log("-------------Recipe 2 --------------------"); +console.log(recipes.recipe2.title); +console.log("Servings: " + recipes.recipe2.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe2.ingredients.length; i++) { + console.log(recipes.recipe2.ingredients[i]); +} +console.log("-------------Recipe 3 --------------------"); +console.log(recipes.recipe3.title); +console.log("Servings: " + recipes.recipe3.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe3.ingredients.length; i++) { + console.log(recipes.recipe3.ingredients[i]); +} +console.log("-------------Recipe 4 --------------------"); +console.log(recipes.recipe4.title); +console.log("Servings: " + recipes.recipe4.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe4.ingredients.length; i++) { + console.log(recipes.recipe4.ingredients[i]); +} +console.log("-------------Recipe 5 --------------------"); +console.log(recipes.recipe5.title); +console.log("Servings: " + recipes.recipe5.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe5.ingredients.length; i++) { + console.log(recipes.recipe5.ingredients[i]); +} \ 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..62a96a25 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,7 +18,10 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here + let createLookupObj = {}; + countryCurrencyCodes.map((country) => createLookupObj[country[0]] = country[1]); + return createLookupObj; + } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..14ae919b 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,7 +19,12 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here +let obj = {}; +obj.name = recipe.name; +obj.items = recipe.ingredients.filter( (e) =>{ + return (!(pantry.fridgeContents.includes(e)) &&!(pantry.cupboardContents.includes(e))) +}) +return obj; } /* ======= TESTS - DO NOT MODIFY ===== @@ -43,11 +48,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..992accea 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,8 +20,20 @@ const MENU = { }; let cashRegister = { - // write code here -} + orderBurger: function (balance) { + if (balance >= MENU.burger) { + balance -= MENU.burger; + } + return balance; + }, + orderFalafel: function (balance) { + if (balance >= MENU.falafel) { + balance -= MENU.falafel; + } + return balance; + }, +}; + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`