diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..605b7fcb 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -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..766e26c5 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,7 +21,8 @@ let basketballTeam = { */ // write code here - +const names = basketballTeam.topPlayers.sort(); +console.log(names.join(" ")) /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..35f09f38 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -23,7 +23,12 @@ 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..e33d8ec8 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -16,6 +16,7 @@ let student = { */ // write code here +student["attendance"] = 90; /* - Write an "if" statement that changes the value of hasPassed to true @@ -26,7 +27,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..b07ac468 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -15,12 +15,13 @@ let car = { }; console.log(car["colour"]); +// In this example we get undefined because car doesn't have property "colour" // Example 2 function sayHelloToUser(user) { console.log(`Hello ${user.firstName}`); } - +// Here a problem, because property name is 'name', not "FirstName" let user = { name: "Mira" }; @@ -34,5 +35,5 @@ let myPet = { "My pet's name is Fluffy"; }, }; - +// Here the problem in function, it doesn't work because it doesn't return anything console.log(myPet.getName()); diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..09fcc4f6 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(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..a8807cb7 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,38 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +const recipe1 = { + title: "Easy kedgeree", + serves: 4, + ingredients: [ + "300g basmati rice", + "600ml chicken stock", + "400g smoked haddock", + "100g frozen peas" + ] +} +const recipe2 = { + title: "Mole", + serves: 2, + ingredients: [ + "Cinnamon", + "Cumin", + "Cocoa" + ] +} + +const recipe3 = { + title: "Cacio e pepe", + serves: 2, + ingredients: [ + "200g bucatini or spaghetti", + "25g butter", + "2 tsp whole black peppercorns, ground, or 1 tsp freshly ground black pepper", + "50g pecorino or parmesan, finely grated" + ] +} +console.log(recipe1) +console.log(recipe2) +console.log(recipe3) diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..0fafb299 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,8 +19,14 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + const currencyCode = {}; + for (let item of countryCurrencyCodes) { + currencyCode[item[0]] = item[1]; + } + return currencyCode; } + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` - To run all exercises/tests in the mandatory folder, run `npm test` diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..9b11bbb2 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,6 +20,16 @@ let pantry = { function createShoppingList(recipe) { // write code here + let missingIngredients = []; + recipe.ingredients.forEach((ingredient) => { + if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)) { + missingIngredients.push(ingredient); + } + }) + return { + name: recipe.name, + items: missingIngredients, +}; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..8ed255d1 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,6 +21,12 @@ const MENU = { let cashRegister = { // write code here + orderBurger: function (balance) { + return balance >= MENU.burger? balance - MENU.burger : balance; + }, + orderFalafel: function (balance) { + return balance >= MENU.falafel? balance - MENU.falafel : balance; + } } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/3-extra/1-count-words.js b/3-extra/1-count-words.js index 9d347ae5..55aa35dd 100644 --- a/3-extra/1-count-words.js +++ b/3-extra/1-count-words.js @@ -25,7 +25,12 @@ function countWords(string) { const wordCount = {}; - + const arr = string.split(" "); + for (let word of arr) { + if (word.length !== 0) { + wordCount[word] = (wordCount[word] || 0) + 1; + } + } // write code here return wordCount;