From 144e1027dd5e71770cc70592722c01e540578e28 Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Tue, 13 Sep 2022 12:12:51 +0100 Subject: [PATCH 01/10] complete exercises A accessing values --- 1-exercises/A-accessing-values/exercise1.js | 12 ++++++------ 1-exercises/A-accessing-values/exercise2.js | 2 +- 1-exercises/A-accessing-values/exercise3.js | 3 +++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..e3dfa76e 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..a18919e5 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["UnitedKingdom"]; // 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..6465aadd 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 +names = basketballTeam.topPlayers.sort() + +console.log(names.join('\r\n')); /* EXPECTED RESULT From af200a1e4082cdd44f89a2365ba9035c81265d7d Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Wed, 14 Sep 2022 11:39:17 +0100 Subject: [PATCH 02/10] complete exercise B setting-values exercise 1&2 --- 1-exercises/B-setting-values/exercise1.js | 5 +++++ 1-exercises/B-setting-values/exercise2.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..d4e60f7c 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 = {name: "Lima"}, +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..bb9a168d 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,6 +27,9 @@ let student = { */ // write code here +if (student["attendance"] >= 90 && student.examScore > 60) { + student.hasPassed = true +} console.log(student); From 15e4edb6b6b00b859d0857a2d260494861a5f88f Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Wed, 14 Sep 2022 11:52:21 +0100 Subject: [PATCH 03/10] complete exercise C undefined-properties --- 1-exercises/C-undefined-properties/exercise.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..2d890931 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -13,8 +13,9 @@ let car = { brand: "Ford", yearsOld: 8, }; +// car.colour = "black" we need to define colour here. -console.log(car["colour"]); +console.log(car["colour"]); // colour is not defined in the car object // Example 2 function sayHelloToUser(user) { @@ -22,7 +23,8 @@ function sayHelloToUser(user) { } let user = { - name: "Mira" + name: "Mira" + //firstName: "Mira" we need to define firstName here instead of name }; sayHelloToUser(user); @@ -30,8 +32,9 @@ sayHelloToUser(user); // Example 3 let myPet = { animal: "Cat", - getName: function() { - "My pet's name is Fluffy"; + getName: function(name) { + + "My pet's name is Fluffy"; // we need to use the return key word }, }; From 5b73a19cb9ff03dc86d34b7f34725d5e59833959 Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Wed, 14 Sep 2022 11:58:58 +0100 Subject: [PATCH 04/10] complete exercise D object-methods --- 1-exercises/D-object-methods/exercise.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..acf9ced9 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,9 +9,13 @@ let student = { // write code here + getName: function(name){ + +return `Student name : ${name} ` + } } -student.getName("Daniel"); +console.log(student.getName("Daniel")); /* EXPECTED RESULT From f1ba9b88987cda5d71024fa03540c5936d6b21ea Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Fri, 16 Sep 2022 16:18:30 +0100 Subject: [PATCH 05/10] complete mandatory folder --- 2-mandatory/1-recipes.js | 56 ++++++++++++++++++++++++++- 2-mandatory/2-currency-code-lookup.js | 5 +++ 2-mandatory/3-shopping-list.js | 13 +++++-- 2-mandatory/4-restaurant.js | 13 ++++++- 4 files changed, 82 insertions(+), 5 deletions(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..b8a2e2d8 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,58 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let favoriteRecipes = { + recipe1: { + Title: "Chicken biryani", + Serves: 2, + Ingredients: ["chicken", "rice", "biryani masala"] + }, + + recipe2: { + Title: "italian pizza", + Serves: 3, + Ingredients: ["flour", "olive oil", "tomatoes"] + }, + + recipe3: { + Title: "Yorkshire budding", + Serves: 1, + Ingredients: ["flour", "eggs", "milk"] + }, + + recipe4: { + Title: "spaghetti bolognese", + Serves: 2, + Ingredients: ["spaghetti", "olive oil", "onions"] + }, + + recipe5: { + Title: "Chocalate cookies", + Serves: 4, + Ingredients: ["sugar", "butter", "flour", "eggs"] + } +} + + +console.log(favoriteRecipes.recipe1.Title); +console.log(`Serves: ${favoriteRecipes.recipe1.Serves}`); +console.log(`Ingredients: ${favoriteRecipes.recipe1.Ingredients}`); + +console.log(favoriteRecipes.recipe2.Title); +console.log(`Serves: ${favoriteRecipes.recipe2.Serves}`); +console.log(`Ingredients: ${favoriteRecipes.recipe2.Ingredients}`); + +console.log(favoriteRecipes.recipe3.Title); +console.log(`Serves: ${favoriteRecipes.recipe3.Serves}`); +console.log(`Ingredients: ${favoriteRecipes.recipe3.Ingredients}`); + +console.log(favoriteRecipes.recipe4.Title); +console.log(`Serves: ${favoriteRecipes.recipe4.Serves}`); +console.log(`Ingredients: ${favoriteRecipes.recipe4.Ingredients}`); + +console.log(favoriteRecipes.recipe5.Title); +console.log(`Serves: ${favoriteRecipes.recipe5.Serves}`); +console.log(`Ingredients: ${favoriteRecipes.recipe5.Ingredients}`); + diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..4680dd86 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 counCurrency = {}; + countryCurrencyCodes.forEach(currency => { + counCurrency[currency[0]] = currency[1] + }); + return counCurrency } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..0813f318 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,9 +19,16 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here -} - + missingItems = recipe.ingredients.filter((items)=> { + return( + !pantry.fridgeContents.includes(items) && !pantry.cupboardContents.includes(items) + ) + }); + return { + name : recipe.name, + items : missingItems, +}; +}; /* ======= 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..d9ac69a2 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,7 +20,18 @@ const MENU = { }; let cashRegister = { - // write code here + orderBurger: function(balance){ + if(balance >= MENU.burger){ + return MENU.burger - balance + } + return balance; +}, + orderFalafel: function(balance){ + if(balance >= MENU.falafel){ + return MENU.falafel - balance + } + return balance + } } /* ======= TESTS - DO NOT MODIFY ===== From 3302a4712cf371bf961ea9149826cb1023ed606c Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Sat, 24 Sep 2022 20:30:36 +0100 Subject: [PATCH 06/10] update exercise A/3 --- 1-exercises/A-accessing-values/exercise3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 6465aadd..d1f57ec3 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -23,7 +23,7 @@ let basketballTeam = { // write code here names = basketballTeam.topPlayers.sort() -console.log(names.join('\r\n')); +console.log(names.join('\n')); /* EXPECTED RESULT From fcf03741d83184efde3459d41dce9362ce5f6fad Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Sat, 24 Sep 2022 20:41:18 +0100 Subject: [PATCH 07/10] update exercise B/1-2 --- 1-exercises/A-accessing-values/exercise3.js | 6 +++++- 1-exercises/B-setting-values/exercise1.js | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index d1f57ec3..7fc74c9b 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -23,7 +23,11 @@ let basketballTeam = { // write code here names = basketballTeam.topPlayers.sort() -console.log(names.join('\n')); +console.log(names.join('\n')); + +// names.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 d4e60f7c..4bf55a75 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -25,9 +25,7 @@ let capitalCities = { // write code here capitalCities.UnitedKingdom.population = 8980000, capitalCities.China.population = 21500000, -capitalCities.Peru = {name: "Lima"}, -capitalCities.Peru.name = "Lima" -capitalCities.Peru.population = 9750000 +capitalCities.Peru = {name: "Lima", population: 9750000} console.log(capitalCities); From 6d7eb98f802b5a53a1e532ab6fbde5060bb43456 Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Sat, 24 Sep 2022 21:26:07 +0100 Subject: [PATCH 08/10] update exercise C and D --- 1-exercises/C-undefined-properties/exercise.js | 8 ++++---- 1-exercises/D-object-methods/exercise.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 2d890931..f79e95fb 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -13,9 +13,9 @@ let car = { brand: "Ford", yearsOld: 8, }; -// car.colour = "black" we need to define colour here. +// car.colour = "black", we need to define colour here. -console.log(car["colour"]); // colour is not defined in the car object +console.log(car["colour"]); //we don't have a property called colour in the object so we get undefined. // Example 2 function sayHelloToUser(user) { @@ -24,7 +24,7 @@ function sayHelloToUser(user) { let user = { name: "Mira" - //firstName: "Mira" we need to define firstName here instead of name + //firstName property does not exist }; sayHelloToUser(user); @@ -34,7 +34,7 @@ let myPet = { animal: "Cat", getName: function(name) { - "My pet's name is Fluffy"; // we need to use the return key word + "My pet's name is Fluffy"; // we need to use the return key word statement }, }; diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index acf9ced9..6346be91 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -11,7 +11,7 @@ let student = { // write code here getName: function(name){ -return `Student name : ${name} ` +return `Student name: ${name} ` } } From caa573573425cfdd2fb5506eb6ea08890db2d92a Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Sat, 24 Sep 2022 21:27:00 +0100 Subject: [PATCH 09/10] update mandatory recipes --- 2-mandatory/1-recipes.js | 99 +++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 47 deletions(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index b8a2e2d8..b749104f 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -25,55 +25,60 @@ // write code here let favoriteRecipes = { - recipe1: { Title: "Chicken biryani", Serves: 2, Ingredients: ["chicken", "rice", "biryani masala"] - }, - - recipe2: { - Title: "italian pizza", - Serves: 3, - Ingredients: ["flour", "olive oil", "tomatoes"] - }, - - recipe3: { - Title: "Yorkshire budding", - Serves: 1, - Ingredients: ["flour", "eggs", "milk"] - }, - - recipe4: { - Title: "spaghetti bolognese", - Serves: 2, - Ingredients: ["spaghetti", "olive oil", "onions"] - }, - - recipe5: { - Title: "Chocalate cookies", - Serves: 4, - Ingredients: ["sugar", "butter", "flour", "eggs"] } -} - - -console.log(favoriteRecipes.recipe1.Title); -console.log(`Serves: ${favoriteRecipes.recipe1.Serves}`); -console.log(`Ingredients: ${favoriteRecipes.recipe1.Ingredients}`); - -console.log(favoriteRecipes.recipe2.Title); -console.log(`Serves: ${favoriteRecipes.recipe2.Serves}`); -console.log(`Ingredients: ${favoriteRecipes.recipe2.Ingredients}`); - -console.log(favoriteRecipes.recipe3.Title); -console.log(`Serves: ${favoriteRecipes.recipe3.Serves}`); -console.log(`Ingredients: ${favoriteRecipes.recipe3.Ingredients}`); - -console.log(favoriteRecipes.recipe4.Title); -console.log(`Serves: ${favoriteRecipes.recipe4.Serves}`); -console.log(`Ingredients: ${favoriteRecipes.recipe4.Ingredients}`); - -console.log(favoriteRecipes.recipe5.Title); -console.log(`Serves: ${favoriteRecipes.recipe5.Serves}`); -console.log(`Ingredients: ${favoriteRecipes.recipe5.Ingredients}`); + // recipe2: { + // Title: "italian pizza", + // Serves: 3, + // Ingredients: ["flour", "olive oil", "tomatoes"] + // }, + + // recipe3: { + // Title: "Yorkshire budding", + // Serves: 1, + // Ingredients: ["flour", "eggs", "milk"] + // }, + + // recipe4: { + // Title: "spaghetti bolognese", + // Serves: 2, + // Ingredients: ["spaghetti", "olive oil", "onions"] + // }, + + // recipe5: { + // Title: "Chocalate cookies", + // Serves: 4, + // Ingredients: ["sugar", "butter", "flour", "eggs"] + // } + + + +console.log(favoriteRecipes.Title); +console.log(`Serves: ${favoriteRecipes.Serves}`); +console.log(`Ingredients: ${favoriteRecipes.Ingredients}`); + +// console.log(favoriteRecipes.recipe2.Title); +// console.log(`Serves: ${favoriteRecipes.recipe2.Serves}`); +// console.log(`Ingredients: ${favoriteRecipes.recipe2.Ingredients}`); + +// console.log(favoriteRecipes.recipe3.Title); +// console.log(`Serves: ${favoriteRecipes.recipe3.Serves}`); +// console.log(`Ingredients: ${favoriteRecipes.recipe3.Ingredients}`); + +// console.log(favoriteRecipes.recipe4.Title); +// console.log(`Serves: ${favoriteRecipes.recipe4.Serves}`); +// console.log(`Ingredients: ${favoriteRecipes.recipe4.Ingredients}`); + +// console.log(favoriteRecipes.recipe5.Title); +// console.log(`Serves: ${favoriteRecipes.recipe5.Serves}`); +// console.log(`Ingredients: ${favoriteRecipes.recipe5.Ingredients}`); + +// console.log(favoriteRecipes.title); +// console.log(`Serves: ${favoriteRecipes.serves}`); +// console.log("Ingredients:") +// favoriteRecipes.Ingredients.forEach((ingredient) => { +// console.log(ingredient); +// }); \ No newline at end of file From 59d85ea5fcde074a0b93a89b4a9ea1103fd372b9 Mon Sep 17 00:00:00 2001 From: micheale2021 Date: Sat, 24 Sep 2022 21:58:26 +0100 Subject: [PATCH 10/10] update recipes and shopping --- 2-mandatory/1-recipes.js | 14 +------------- 2-mandatory/3-shopping-list.js | 8 ++++---- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index b749104f..42b51a3f 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -30,19 +30,7 @@ let favoriteRecipes = { Ingredients: ["chicken", "rice", "biryani masala"] } - // recipe2: { - // Title: "italian pizza", - // Serves: 3, - // Ingredients: ["flour", "olive oil", "tomatoes"] - // }, - - // recipe3: { - // Title: "Yorkshire budding", - // Serves: 1, - // Ingredients: ["flour", "eggs", "milk"] - // }, - - // recipe4: { + // Title: "spaghetti bolognese", // Serves: 2, // Ingredients: ["spaghetti", "olive oil", "onions"] diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index 0813f318..a683afe1 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,10 +19,10 @@ let pantry = { }; function createShoppingList(recipe) { - missingItems = recipe.ingredients.filter((items)=> { - return( - !pantry.fridgeContents.includes(items) && !pantry.cupboardContents.includes(items) - ) + let missingItems = recipe.ingredients.filter((item)=> { + + return !pantry.fridgeContents.includes(item) && !pantry.cupboardContents.includes(item) + }); return { name : recipe.name,