From e7b4704e56fb15337a91763956b404e6d0ed079a Mon Sep 17 00:00:00 2001 From: Jade Jones Date: Sat, 10 Sep 2022 10:59:08 +0100 Subject: [PATCH 1/9] a --- 1-exercises/A-accessing-values/exercise1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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}`); From 139a11d5db0f3e80a8dc200a7c5d5b9077d09ba4 Mon Sep 17 00:00:00 2001 From: JadeJones2022 <100792140+JadeJones2022@users.noreply.github.com> Date: Sun, 11 Sep 2022 09:39:20 +0100 Subject: [PATCH 2/9] a --- 1-exercises/A-accessing-values/exercise2.js | 2 +- 1-exercises/A-accessing-values/exercise3.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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..84a76896 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,6 +21,10 @@ let basketballTeam = { */ // write code here +let sortedPlayers = basketballTeam.topPlayers.sort() +console.log(sortedPlayers[0]) +console.log(sortedPlayers[1]) +console.log(sortedPlayers[2]) /* EXPECTED RESULT From 3fc9a85fe7ef0d37780a95d8ecd8f562a315079e Mon Sep 17 00:00:00 2001 From: JadeJones2022 <100792140+JadeJones2022@users.noreply.github.com> Date: Sun, 11 Sep 2022 09:43:45 +0100 Subject: [PATCH 3/9] b --- 1-exercises/B-setting-values/exercise1.js | 4 ++++ 1-exercises/B-setting-values/exercise2.js | 2 ++ 2 files changed, 6 insertions(+) diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..581104b3 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -24,6 +24,10 @@ let capitalCities = { // write code here +capitalCities.UnitedKingdom.population = 8980000 +capitalCities.China.population = 21500000 +capitalCities.Peru = {name: "Lima", population:975000} + 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..a3c10ace 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -17,6 +17,8 @@ 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 From cda413767fc63f121f81ba44901dcdcf44dc3524 Mon Sep 17 00:00:00 2001 From: JadeJones2022 <100792140+JadeJones2022@users.noreply.github.com> Date: Sun, 11 Sep 2022 09:46:35 +0100 Subject: [PATCH 4/9] c --- 1-exercises/C-undefined-properties/exercise.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..29c5039f 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -16,6 +16,8 @@ let car = { console.log(car["colour"]); +// this is undefined because there is no key for colour + // Example 2 function sayHelloToUser(user) { console.log(`Hello ${user.firstName}`); @@ -27,6 +29,8 @@ let user = { sayHelloToUser(user); +// this is undefined because there is no key for firstName just name + // Example 3 let myPet = { animal: "Cat", @@ -36,3 +40,4 @@ let myPet = { }; console.log(myPet.getName()); +//There is no name set in the myPet object \ No newline at end of file From 604a70e2f59b8b2a8fb31045fd51fbf8bfe2fe17 Mon Sep 17 00:00:00 2001 From: JadeJones2022 <100792140+JadeJones2022@users.noreply.github.com> Date: Sun, 11 Sep 2022 09:48:33 +0100 Subject: [PATCH 5/9] d --- 1-exercises/D-object-methods/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..f2bc4b75 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -8,7 +8,9 @@ */ let student = { - // write code here + getName: function(name){ + console.log(`Student name: ${name}`) + } } student.getName("Daniel"); From 39d66fa2ff68f1e7498003c1928dd264611d363a Mon Sep 17 00:00:00 2001 From: JadeJones2022 <100792140+JadeJones2022@users.noreply.github.com> Date: Sun, 11 Sep 2022 10:16:41 +0100 Subject: [PATCH 6/9] man 1 --- 2-mandatory/1-recipes.js | 77 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..a2b162a8 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,79 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let recipe = { + Pancakes:{ + title: "Pancakes", + serves: 4, + Ingredients: ["Eggs", "Flour", "Milk", "Butter"] + }, + LemonCake:{ + title: "Lemon Cake", + serves: 8, + Ingredients: ["Eggs", "Flour", "Butter", "Sugar", "Lemons"] + }, + Oats:{ + title: "Overnight Oats", + serves: 4, + Ingredients: ["Oats", "Apple", "Raisins", "Honey", "Yoghurt", "Milk"] + }, + Fritatta:{ + title: "Fritatta", + serves: 6, + Ingredients: ["Eggs", "Chicken", "Chorizo", "Vegetables"] + }, + Soup:{ + title: "Soup", + serves: 8, + Ingredients: ["Onions", "Vegetables", "Chicken", "Stock"] + + } + + +}; + +console.log(recipe.Pancakes.title) +console.log(`Serves: ${recipe.Pancakes.serves}`) +console.log(`Ingredients:`) +console.log(recipe.Pancakes.Ingredients[0]) +console.log(recipe.Pancakes.Ingredients[1]) +console.log(recipe.Pancakes.Ingredients[2]) +console.log(recipe.Pancakes.Ingredients[3]); + +console.log(recipe.LemonCake.title) +console.log(`Serves: ${recipe.LemonCake.serves}`) +console.log(`Ingredients:`) +console.log(recipe.LemonCake.Ingredients[0]) +console.log(recipe.LemonCake.Ingredients[1]) +console.log(recipe.LemonCake.Ingredients[2]) +console.log(recipe.LemonCake.Ingredients[3]) +console.log(recipe.LemonCake.Ingredients[4]); + + +console.log(recipe.Oats.title) +console.log(`Serves: ${recipe.Oats.serves}`) +console.log(`Ingredients:`) +console.log(recipe.Oats.Ingredients[0]) +console.log(recipe.Oats.Ingredients[1]) +console.log(recipe.Oats.Ingredients[2]) +console.log(recipe.Oats.Ingredients[3]) +console.log(recipe.Oats.Ingredients[4]) +console.log(recipe.Oats.Ingredients[5]); + +console.log(recipe.Fritatta.title) +console.log(`Serves: ${recipe.Fritatta.serves}`) +console.log(`Ingredients:`) +console.log(recipe.Fritatta.Ingredients[0]) +console.log(recipe.Fritatta.Ingredients[1]) +console.log(recipe.Fritatta.Ingredients[2]) +console.log(recipe.Fritatta.Ingredients[3]); + +console.log(recipe.Soup.title) +console.log(`Serves: ${recipe.Soup.serves}`) +console.log(`Ingredients:`) +console.log(recipe.Soup.Ingredients[0]) +console.log(recipe.Soup.Ingredients[1]) +console.log(recipe.Soup.Ingredients[2]) +console.log(recipe.Soup.Ingredients[3]); From d004ebac9bd1864a292aabe776c57385d13bdbed Mon Sep 17 00:00:00 2001 From: JadeJones2022 <100792140+JadeJones2022@users.noreply.github.com> Date: Sun, 11 Sep 2022 10:58:37 +0100 Subject: [PATCH 7/9] man 1 and 2 --- 2-mandatory/2-currency-code-lookup.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..be00eb59 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -16,9 +16,25 @@ const COUNTRY_CURRENCY_CODES = [ ["NG", "NGN"], ["MX", "MXN"], ]; - +/* function createLookup(countryCurrencyCodes) { - // write code here + let object = countryCurrencyCodes.reduce((result, [key, value]) => { + result[key] = value; + return result; + }) + console.log(object) +}*/ + +function createLookup(countryCurrencyCodes){ +const convertArrayToObject = (array, key) => { + const initialValue = {}; + return array.reduce((obj, item) => { + return { + countryCurrencyCodes, + [item[key]]: item, + }; + }, initialValue); +}; } /* ======= TESTS - DO NOT MODIFY ===== From b1cd09563dd7a0e185f0936374009181a6ccf244 Mon Sep 17 00:00:00 2001 From: JadeJones2022 <100792140+JadeJones2022@users.noreply.github.com> Date: Sun, 11 Sep 2022 11:23:21 +0100 Subject: [PATCH 8/9] shopping list --- 2-mandatory/2-currency-code-lookup.js | 22 +++++----------------- 2-mandatory/3-shopping-list.js | 7 ++++++- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index be00eb59..b8d2eade 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -16,25 +16,13 @@ const COUNTRY_CURRENCY_CODES = [ ["NG", "NGN"], ["MX", "MXN"], ]; -/* -function createLookup(countryCurrencyCodes) { - let object = countryCurrencyCodes.reduce((result, [key, value]) => { - result[key] = value; - return result; - }) - console.log(object) -}*/ function createLookup(countryCurrencyCodes){ -const convertArrayToObject = (array, key) => { - const initialValue = {}; - return array.reduce((obj, item) => { - return { - countryCurrencyCodes, - [item[key]]: item, - }; - }, initialValue); -}; + let object ={} + for(let element of countryCurrencyCodes){ + object[element[0]] = element[1]; + } + return object } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..fc1a0181 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 needToBuy = {} + needToBuy.name = recipe.name + needToBuy.items = recipe.ingredients.filter((element) => { + return(!(pantry.fridgeContents.includes(element))&&!(pantry.cupboardContents.includes(element))) + }) + return needToBuy } /* ======= TESTS - DO NOT MODIFY ===== From a48bb2439b7bf9b59a532d33d72aea478bbca122 Mon Sep 17 00:00:00 2001 From: JadeJones2022 <100792140+JadeJones2022@users.noreply.github.com> Date: Sun, 11 Sep 2022 11:33:38 +0100 Subject: [PATCH 9/9] man 4 --- 2-mandatory/4-restaurant.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..cd700c1b 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,6 +21,20 @@ const MENU = { let cashRegister = { // write code here + orderBurger: function(balance){ + if (balance >= MENU.burger) { + return(balance - 6.5) + } else { + return(balance) + } + }, + orderFalafel: function(balance){ + if (balance >= MENU.falafel) { + return(balance - 7.25) + } else { + return(balance) + } + }, } /* ======= TESTS - DO NOT MODIFY =====