From ba1a7ed541edff3ba50c5ac20170821a932ec086 Mon Sep 17 00:00:00 2001 From: Jihad Omer Date: Thu, 6 Oct 2022 10:15:48 +0100 Subject: [PATCH] Done --- 1-exercises/A-accessing-values/exercise1.js | 4 +- 1-exercises/A-accessing-values/exercise2.js | 3 +- 1-exercises/A-accessing-values/exercise3.js | 8 +- 1-exercises/B-setting-values/exercise1.js | 7 +- 1-exercises/B-setting-values/exercise2.js | 5 + .../C-undefined-properties/exercise.js | 8 +- 1-exercises/D-object-methods/exercise.js | 11 ++- 2-mandatory/1-recipes.js | 92 ++++++++++++++++++- 2-mandatory/2-currency-code-lookup.js | 20 +++- 2-mandatory/3-shopping-list.js | 15 +++ 2-mandatory/4-restaurant.js | 17 +++- 11 files changed, 175 insertions(+), 15 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}`); diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index 5b523ace..704b6ca5 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -17,7 +17,8 @@ let capitalCities = { */ let myCountry = "UnitedKingdom"; -let myCapitalCity; // complete the code +// let myCapitalCity = capitalCities[myCountry] ; // complete the code +let myCapitalCity = capitalCitiesUnitedKingdom ; // 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..65e2bfee 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -20,7 +20,13 @@ let basketballTeam = { - console.logs the name of each player on a new line */ -// write code here +const topPlayer = basketballTeam.topPlayers; + +// console.log(topPlayer) => for test + +const thebest = () => topPlayer.sort(); + +console.log(thebest()) /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..cacf667e 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..8b3bce3f 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -16,6 +16,11 @@ let student = { */ // write code here +student['attendance'] = 90; + +if (student['examScore'] >= 60) { + student['hasPassed'] = true; +} /* - Write an "if" statement that changes the value of hasPassed to true diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..8a9d535c 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -14,7 +14,7 @@ let car = { yearsOld: 8, }; -console.log(car["colour"]); +console.log(car["colour"]); // there is no propetey called 'colour' in in the object // Example 2 function sayHelloToUser(user) { @@ -25,14 +25,14 @@ let user = { name: "Mira" }; -sayHelloToUser(user); +sayHelloToUser(user); // there is no propetey called 'firstName' in in the object // Example 3 let myPet = { animal: "Cat", getName: function() { - "My pet's name is Fluffy"; + "My pet's name is Fluffy"; }, }; -console.log(myPet.getName()); +console.log(myPet.getName()); // there is no propetey called firstName in in the objectThe function has no 'return' diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..fcaee87c 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,9 +9,16 @@ let student = { // write code here -} -student.getName("Daniel"); + getName: function (name) { + console.log(`Student name: ${name}`); + }, +}; + +student.getName("Daniel") + + + /* EXPECTED RESULT diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..388e23c2 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,94 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let one = { +title : 'EggOmlet', +serving : 2 , +ingrediants : ['4 eggs', 'oil' , 'tomato' , 'onion', 'salt' ], + +} +let tow = { +title : 'burger', +serving : 2 , +ingrediants : ['meat', 'oil' , 'tomato' , 'onion', 'salt' ], + +} +let three = { +title : 'chicken', +serving : 2 , +ingrediants : ['chiken', 'oil' , 'tomato' , 'onion', 'salt' ], + +} +let four = { +title : 'fish', +serving : 2 , +ingrediants : ['fish', 'oil' , 'tomato' , 'onion', 'salt' ], + +} +let five = { +title : 'vegan', +serving : 2 , +ingrediants : ['mix vegs', 'oil' , 'tomato' , 'onion', 'salt' ], + +} + +console.log(one.title); +console.log(`severs : ${one.serving}`); +console.log(`Ingrediants : + ${one.ingrediants[0]} + ${one.ingrediants[1]} + ${one.ingrediants[2]} + ${one.ingrediants[3]} + ${one.ingrediants[4]} `); +console.log(tow.title); + + + + +console.log(`severs : ${tow.serving}`); +console.log(`Ingrediants : + ${tow.ingrediants[0]} + ${tow.ingrediants[1]} + ${tow.ingrediants[2]} + ${tow.ingrediants[3]} + ${tow.ingrediants[4]} `); + + +console.log(three.title); +console.log(`severs : ${three.serving}`); +console.log(`Ingrediants : + ${three.ingrediants[0]} + ${three.ingrediants[1]} + ${three.ingrediants[2]} + ${three.ingrediants[3]} + ${three.ingrediants[4]} `); + + + +console.log(four.title); +console.log(`severs : ${four.serving}`); +console.log(`Ingrediants : + ${four.ingrediants[0]} + ${four.ingrediants[1]} + ${four.ingrediants[2]} + ${four.ingrediants[3]} + ${four.ingrediants[4]} `); + + + +console.log(five.title); +console.log(`severs : ${five.serving}`); +console.log(`Ingrediants : + ${five.ingrediants[0]} + ${five.ingrediants[1]} + ${five.ingrediants[2]} + ${five.ingrediants[3]} + ${five.ingrediants[4]} `); + + +// console.log(tow); +// console.log(three); +// console.log(four); +// console.log(five); \ 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..f28f19da 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,7 +19,25 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here -} + let newObj = {} + for (let x of countryCurrencyCodes ) { + newObj[x[0]] = x[1]; + + } +return newObj; + } + + + + + + + + + + + + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..1f407bc8 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,8 +20,23 @@ let pantry = { function createShoppingList(recipe) { // write code here + + let final = new Object(); + let result = []; + for (ingredient of recipe.ingredients) { + if ( + !pantry.fridgeContents.includes(ingredient) && + !pantry.cupboardContents.includes(ingredient) + ) { + result.push(ingredient); + } + } + final["name"] = recipe.name; + final["items"] = result; + return final; } + /* ======= 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..95ba00ea 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,8 +20,21 @@ const MENU = { }; let cashRegister = { - // write code here -} + orderBurger: function (balance) { + if (balance >= MENU.burger) { + return balance -= MENU.burger + } + return balance + }, + orderFalafel : function(balance) { + if (balance >= MENU.falafel) { + return balance -= MENU.falafel + } + return balance + } + } + + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`