From 9c4faab230d2ac707a5ad295affac5101a059eee Mon Sep 17 00:00:00 2001 From: Refik Gulak <74262442+Refik48@users.noreply.github.com> Date: Sun, 2 Oct 2022 13:58:25 +0100 Subject: [PATCH 1/7] Exercise A was completed --- 1-exercises/A-accessing-values/exercise1.js | 8 ++++---- 1-exercises/A-accessing-values/exercise2.js | 2 +- 1-exercises/A-accessing-values/exercise3.js | 7 +++++-- 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..dcf5a5ce 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -8,7 +8,7 @@ let dog = { breed: "Dalmatian", name: "Spot", isHungry: true, - happiness: 6 + happiness: 6, }; /* @@ -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}`); @@ -25,4 +25,4 @@ console.log(`${dogName} is a ${dogBreed}`); Spot is a Dalmatian -*/ \ No newline at end of file +*/ 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..ae8cb2f9 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,7 +21,10 @@ let basketballTeam = { */ // write code here - +basketballTeam.topPlayers.sort(); +for (let i = 0; i < basketballTeam.topPlayers.length; i++) { + console.log(basketballTeam.topPlayers[i]); +} /* EXPECTED RESULT @@ -29,4 +32,4 @@ let basketballTeam = { Michael Jordan Scottie Pippen -*/ \ No newline at end of file +*/ From efde10e3f9fcddef36a3087fff5e2b7794afd2af Mon Sep 17 00:00:00 2001 From: Refik Gulak <74262442+Refik48@users.noreply.github.com> Date: Tue, 4 Oct 2022 11:40:56 +0100 Subject: [PATCH 2/7] Exercise B was completed --- 1-exercises/B-setting-values/exercise1.js | 5 +++++ 1-exercises/B-setting-values/exercise2.js | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..a83171bc 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 = {}; +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..e4e86470 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -15,7 +15,7 @@ let student = { - Set the value of attendance to 90 */ -// write code here +student["attendance"] = 90; /* - Write an "if" statement that changes the value of hasPassed to true @@ -26,7 +26,9 @@ let student = { */ // write code here - +if (student.attendance >= 90 && student.examScore > 60) { + student["hasPassed"] = true; +} console.log(student); /* EXPECTED RESULT From 6d42155e9e630c9f829b0d92076503957da10f25 Mon Sep 17 00:00:00 2001 From: Refik Gulak <74262442+Refik48@users.noreply.github.com> Date: Tue, 4 Oct 2022 11:51:16 +0100 Subject: [PATCH 3/7] Exercise B was comleted --- 1-exercises/C-undefined-properties/exercise.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..ca13e6a4 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 color property! // Example 2 function sayHelloToUser(user) { @@ -22,17 +22,17 @@ function sayHelloToUser(user) { } let user = { - name: "Mira" + name: "Mira", }; -sayHelloToUser(user); +sayHelloToUser(user); // There is no user firstName property. // Example 3 let myPet = { animal: "Cat", - getName: function() { + getName: function () { "My pet's name is Fluffy"; }, }; -console.log(myPet.getName()); +console.log(myPet.getName()); // There is no return function. From f926b3d91c2d6cc87f55987ecd899e4e56a7dd9c Mon Sep 17 00:00:00 2001 From: Refik Gulak <74262442+Refik48@users.noreply.github.com> Date: Tue, 4 Oct 2022 11:56:04 +0100 Subject: [PATCH 4/7] Exercise D was completed --- 1-exercises/D-object-methods/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..0d289fd7 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,6 +9,7 @@ let student = { // write code here + getName : (name) => console.log(`Student name: ${name}`) } student.getName("Daniel"); From 232249fa8916a5fcc05b5d84113ba2ffea178409 Mon Sep 17 00:00:00 2001 From: Refik Gulak <74262442+Refik48@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:56:59 +0100 Subject: [PATCH 5/7] Mandatory 1 was completed --- 2-mandatory/1-recipes.js | 66 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..7c8637c1 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,68 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let recipes = { + recipe1: { + title: "Pasta", + servings: 6, + ingredients: ["Pasta", "ketchub", "salt"], + }, + recipe2: { + title: "Pizza", + servings: 4, + ingredients: ["mince", "tomato", "mushroom", "chese", "onion"], + }, + recipe3: { + title: "manti", + serving: 4, + ingredients: [" dough", "minced meat", "tomato sauce", "yogurt"], + }, + recipe4: { + title: "icli kofte", + serving: 8, + ingredients: ["fine wheat", "minced-meat", "vegetable oil", "spices"], + }, + recipe5: { + title: "rice", + servings: 5, + ingredients: ["rice", "butter", "salt", "hot water"], + }, +}; +console.log("-------------Recipe 1 --------------------"); +console.log(recipes.recipe1.title); +console.log("Servings: " + recipes.recipe1.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe1.ingredients.length;i++){ + + console.log(recipes.recipe1.ingredients[i]); +} +console.log("-------------Recipe 2 --------------------"); +console.log(recipes.recipe2.title); +console.log("Servings: " + recipes.recipe2.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe2.ingredients.length; i++) { + console.log(recipes.recipe2.ingredients[i]); +} +console.log("-------------Recipe 3 --------------------"); +console.log(recipes.recipe3.title); +console.log("Servings: " + recipes.recipe3.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe3.ingredients.length; i++) { + console.log(recipes.recipe3.ingredients[i]); +} +console.log("-------------Recipe 4 --------------------"); +console.log(recipes.recipe4.title); +console.log("Servings: " + recipes.recipe4.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe4.ingredients.length; i++) { + console.log(recipes.recipe4.ingredients[i]); +} +console.log("-------------Recipe 5 --------------------"); +console.log(recipes.recipe5.title); +console.log("Servings: " + recipes.recipe5.servings); +console.log("Ingredients:"); +for (let i = 0; i < recipes.recipe5.ingredients.length; i++) { + console.log(recipes.recipe5.ingredients[i]); +} \ No newline at end of file From ad68f71e0cf5a484d9c4ea49af250f8677588a60 Mon Sep 17 00:00:00 2001 From: Refik Gulak <74262442+Refik48@users.noreply.github.com> Date: Wed, 5 Oct 2022 13:16:02 +0100 Subject: [PATCH 6/7] Mandatory 2 was completed --- 2-mandatory/2-currency-code-lookup.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..62a96a25 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,7 +18,10 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here + let createLookupObj = {}; + countryCurrencyCodes.map((country) => createLookupObj[country[0]] = country[1]); + return createLookupObj; + } /* ======= TESTS - DO NOT MODIFY ===== From 911bb774e63c347e1a85e42fb4b5a756b1cd5d9e Mon Sep 17 00:00:00 2001 From: Refik Gulak <74262442+Refik48@users.noreply.github.com> Date: Wed, 12 Oct 2022 01:48:32 +0100 Subject: [PATCH 7/7] Mandatory done --- 2-mandatory/3-shopping-list.js | 20 ++++++++++++++++---- 2-mandatory/4-restaurant.js | 16 ++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..14ae919b 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 obj = {}; +obj.name = recipe.name; +obj.items = recipe.ingredients.filter( (e) =>{ + return (!(pantry.fridgeContents.includes(e)) &&!(pantry.cupboardContents.includes(e))) +}) +return obj; } /* ======= TESTS - DO NOT MODIFY ===== @@ -43,11 +48,18 @@ test("createShoppingList works for pancakes recipe", () => { test("createShoppingList works for margherita pizza recipe", () => { let recipe2 = { name: "margherita pizza", - ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella"], + ingredients: [ + "flour", + "salt", + "yeast", + "tinned tomatoes", + "oregano", + "mozarella", + ], }; expect(createShoppingList(recipe2)).toEqual({ name: "margherita pizza", - items: ["flour", "yeast", "mozarella"] + items: ["flour", "yeast", "mozarella"], }); -}); \ No newline at end of file +}); diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..992accea 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,8 +20,20 @@ const MENU = { }; let cashRegister = { - // write code here -} + orderBurger: function (balance) { + if (balance >= MENU.burger) { + balance -= MENU.burger; + } + return balance; + }, + orderFalafel: function (balance) { + if (balance >= MENU.falafel) { + balance -= MENU.falafel; + } + return balance; + }, +}; + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`