From 40ad6312df90f64e631d614b2c9d7d81d1b385a8 Mon Sep 17 00:00:00 2001 From: Jihad7898 <107761291+Barryeasy90@users.noreply.github.com> Date: Sat, 15 Oct 2022 06:28:34 +0100 Subject: [PATCH] Exercises' solved & Mandatories updated --- 1-exercises/A-accessing-values/exercise1.js | 14 +++---- 1-exercises/A-accessing-values/exercise2.js | 2 +- 1-exercises/A-accessing-values/exercise3.js | 1 + 1-exercises/B-setting-values/exercise1.js | 7 +++- 1-exercises/B-setting-values/exercise2.js | 5 +++ .../C-undefined-properties/exercise.js | 6 +-- 1-exercises/D-object-methods/exercise.js | 5 ++- 2-mandatory/1-recipes.js | 38 ++++++++++++++++++- 2-mandatory/2-currency-code-lookup.js | 14 +++++++ 2-mandatory/3-shopping-list.js | 9 +++++ 2-mandatory/4-restaurant.js | 18 ++++++++- 11 files changed, 104 insertions(+), 15 deletions(-) diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..3b1ed297 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,10 +16,10 @@ let dog = { Log the name and breed of this dog using dot notation. */ -let dogName; // complete the code -let dogBreed; // complete the code +// let dog.name; // complete the code +// let dog.breed; // complete the code -console.log(`${dogName} is a ${dogBreed}`); +console.log(`${dog.name} is a ${dog.breed}`); /* EXPECTED RESULT 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..e88c0929 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,6 +21,7 @@ let basketballTeam = { */ // write code here +console.log(`${basketballTeam["topPlayers"].sort()}`) /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..ef16fd2a 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..6303f88b 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -16,6 +16,8 @@ let student = { */ // write code here +student["attendance"] = 90 + /* - Write an "if" statement that changes the value of hasPassed to true @@ -26,6 +28,9 @@ let student = { */ // write code here + if (student["attendance"] >= 90 && student["examScore"] > 60){ + student["hasPassed"] = true; + } console.log(student); diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..54460343 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"]);// colour property is not declare for the car object // Example 2 function sayHelloToUser(user) { @@ -25,7 +25,7 @@ let user = { name: "Mira" }; -sayHelloToUser(user); +sayHelloToUser(user);// the firstName property does not declared, trying to access property whic is not decalared will return undifined // Example 3 let myPet = { @@ -35,4 +35,4 @@ let myPet = { }, }; -console.log(myPet.getName()); +console.log(myPet.getName());// the function getName does not have return diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..5b54f17f 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,7 +9,10 @@ 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..c5cd24dc 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,40 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here +molerecipe ={ + title : "Mole", + servings : 2, + ingredients : ["cinnamon", "cumin", "cocoa"] +} +cheprecipe = { +title: "Chep", +servings: 4, +ingredients: ["Fish", "Oil", "Onion", "Magui", "Galic", "Rice"] +} +gingerrecipe = { + title: "Gingerbeer", + servings: 3, + ingredients: ["Ginger", "Sugar", "Wanter", "Arom"] + +} +console.log(molerecipe.title) +console.log(`Serves:${molerecipe.servings}`) +console.log("Ingredients:") +for (item of molerecipe.ingredients){ + console.log(item); +} +console.log("--------------------") +console.log(gingerrecipe.title) +console.log(`Serves:${gingerrecipe.servings}`) +console.log("Ingredients:") +for (item of gingerrecipe.ingredients){ + console.log(item); +} +console.log("--------------------") +console.log(cheprecipe.title) +console.log(`Serves:${cheprecipe.servings}`) +console.log("Ingredients:") +for (item of cheprecipe.ingredients){ + console.log(item); +} diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..a2a3771f 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,20 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + let newObject = {}; + for (element of countryCurrencyCodes ){ + let country = element[0]; + let currency = element[1]; + newObject[country] = currency; + // newObject.element[0][0] = element[0][1]; + } + + // countryCurrencyCodes.map(item=> {forEach(element => { + // console.log(element+":"+element[1]) + // });} + + // ) + return newObject; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..90809b9d 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,6 +20,15 @@ let pantry = { function createShoppingList(recipe) { // write code here + let missingIngredients = recipe.ingredients.filter( + (ingredient) => { + return !pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(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..8793738a 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,10 +21,26 @@ const MENU = { let cashRegister = { // write code here + orderBurger: function(balance) { + let finalBalance = balance; + let isBalanceBigEnough = balance - MENU.burger >= 0; + if (isBalanceBigEnough) { + finalBalance = balance - MENU.burger; + } + return finalBalance; + }, + orderFalafel: function(balance) { + let finalBalance = balance; + let isBalanceBigEnough = balance - MENU.falafel >= 0; + if (isBalanceBigEnough) { + finalBalance = balance - MENU.falafel; + } + return finalBalance; + }, } /* ======= TESTS - DO NOT MODIFY ===== -- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` +- To run the tests for this exercise, run `cl` - To run all exercises/tests in the mandatory folder, run `npm test` - (Reminder: You must have run `npm install` one time before this will work!) */