diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..4e8d0f5f 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..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..bb2d28bd 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -22,6 +22,7 @@ let basketballTeam = { // write code here +console.log(basketballTeam.topPlayers.sort()); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..c13e7776 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..c0a950a8 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -17,6 +17,9 @@ let student = { // write code here +student["attendance"] = 90; + + /* - Write an "if" statement that changes the value of hasPassed to true if the student has attendance that is equal or greater than 90 @@ -26,6 +29,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..417a0738 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -14,11 +14,11 @@ let car = { yearsOld: 8, }; -console.log(car["colour"]); +console.log(car["colour"]); //color property is not added to the car object // Example 2 function sayHelloToUser(user) { - console.log(`Hello ${user.firstName}`); + console.log(`Hello ${user.firstName}`); // does not have a property firstName } let user = { @@ -35,4 +35,4 @@ let myPet = { }, }; -console.log(myPet.getName()); +console.log(myPet.getName()); //object needs a return statement diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..74786f4c 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,9 +9,12 @@ let student = { // write code here + getName: function(name) { + console.log(`Student name: ${name}`); + } } -student.getName("Daniel"); +student.getName("Daniel") /* EXPECTED RESULT diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..71be7519 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,45 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let recipeCard1 = { + title: "Mole", + serves: 2, + ingredients: ["cinnamon", "cumin", "cocoa"] +} + +console.log(recipeCard1); + +let recipeCard2 = { + title: "Soup", + serves: 2, + ingredients: ["onion", "tomato", "cilantro", "carrot"] +} + +console.log(recipeCard2); + +let recipeCard3 = { + title: "Omelette", + serves: 2, + ingredients: ["eggs", "butter", "pepper", "salt", "cheese"] +} + +console.log(recipeCard3); + +let recipeCard4 = { + title: "Pizza", + serves: 2, + ingredients: ["flour", "tomato", "cheese", "chicken", "mushroom"] +} + +console.log(recipeCard4); + +let recipeCard5 = { + title: "Cake", + serves: 2, + ingredients: ["flour", "chocolate", "milk", "butter", "sugar"] +} + +console.log(recipeCard5); + diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..ee6c213b 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,7 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + return Object.fromEntries(countryCurrencyCodes); } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..3af7afd1 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -10,7 +10,7 @@ The createShoppingList function should return an object with two properties: - "name" of the recipe, which is a string, - - "items", which is an arry of the missing ingredients that need to be on the shopping list + - "items", which is an array of the missing ingredients that need to be on the shopping list */ let pantry = { @@ -19,9 +19,22 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here + + const allIngredients = Object.values(pantry).flat(); + const missingItems = recipe.ingredients.filter((ingredient, index, array) => { + if (allIngredients.includes(ingredient)) { + return false; + } + return true; + }); + const objectToReturn = { + name: recipe.name, + items: missingItems, + }; + return objectToReturn; } + /* ======= 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..848d931a 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,8 +20,22 @@ 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`