From 3691ee74e2c3570d2a1791b69566eb4796a69248 Mon Sep 17 00:00:00 2001 From: KamNik0044 <105980197+KamNik0044@users.noreply.github.com> Date: Wed, 5 Oct 2022 17:33:46 +0100 Subject: [PATCH] All exercises and mandatories done --- 1-exercises/A-accessing-values/exercise1.js | 12 ++++++------ 1-exercises/A-accessing-values/exercise2.js | 2 +- 1-exercises/A-accessing-values/exercise3.js | 3 +++ 1-exercises/B-setting-values/exercise1.js | 4 +++- 1-exercises/B-setting-values/exercise2.js | 6 ++++-- 1-exercises/C-undefined-properties/exercise.js | 6 +++--- 1-exercises/D-object-methods/exercise.js | 3 +++ 2-mandatory/1-recipes.js | 12 +++++++++++- 2-mandatory/2-currency-code-lookup.js | 5 +++++ 2-mandatory/3-shopping-list.js | 17 +++++++++++++++++ 2-mandatory/4-restaurant.js | 12 ++++++++++++ 11 files changed, 68 insertions(+), 14 deletions(-) diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..d2ab7367 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..91539d5b 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,6 +21,9 @@ let basketballTeam = { */ // write code here +basketballTeam.topPlayers.sort().forEach((player) => { + console.log(player); +}); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..52dc5212 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -23,7 +23,9 @@ let capitalCities = { */ // 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..9b1ad887 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -16,7 +16,7 @@ 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,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..a611faa8 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -14,13 +14,13 @@ let car = { yearsOld: 8, }; -console.log(car["colour"]); +console.log(car["colour"]); // color is not defined in the properties "{}" // Example 2 function sayHelloToUser(user) { console.log(`Hello ${user.firstName}`); } - + // the firstName is not defined // let user = { name: "Mira" }; @@ -35,4 +35,4 @@ let myPet = { }, }; -console.log(myPet.getName()); +console.log(myPet.getName()); // the function missing return statement diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..a8303480 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,6 +9,9 @@ let student = { // write code here + getName: function(string) { + console.log(`Student name: ${string}`); + } } student.getName("Daniel"); diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..e4760585 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,14 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let recipe = { + title: "Salad-Snowflake", + servings: 4, + ingredients: ["strained yogurt", "pickles", "walnuts", "cloves of garlic", "bunch dill", "Olive oil"], +}; +console.log(recipe.title); +console.log(`Serves: ${recipe.servings}`); +console.log("Ingredients:"); +recipe.ingredients.forEach((ingredient) => console.log(ingredient)); \ 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..afac5b63 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,11 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + let countryCurrency = {}; + countryCurrencyCodes.forEach(currency => { + countryCurrency[currency[0]] = currency[1] + }); + return countryCurrency } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..9d60de07 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,6 +20,23 @@ let pantry = { function createShoppingList(recipe) { // write code here + let recipeName = recipe.name; + let recipeIngredients = recipe.ingredients; + + let emptyContainer = []; + + recipeIngredients.forEach((item) => { + if ( + !pantry.fridgeContents.includes(item) && + !pantry.cupboardContents.includes(item) + ) { + emptyContainer.push(item); + } + }); + return { + name: recipeName, + items: emptyContainer, + }; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..d638f57f 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,6 +21,18 @@ 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 =====