From 63f14b40e55f0e074f248141b928b91f795aa195 Mon Sep 17 00:00:00 2001 From: leilafaez Date: Tue, 4 Oct 2022 15:07:25 +0100 Subject: [PATCH 1/3] Update exercise folder --- 1-exercises/A-accessing-values/exercise1.js | 4 ++-- 1-exercises/A-accessing-values/exercise2.js | 2 +- 1-exercises/A-accessing-values/exercise3.js | 3 ++- 1-exercises/B-setting-values/exercise1.js | 3 +++ 1-exercises/B-setting-values/exercise2.js | 5 ++++- 1-exercises/C-undefined-properties/exercise.js | 6 +++--- 1-exercises/D-object-methods/exercise.js | 5 ++++- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..694330ac 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..c90c19ad 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..8cdf51f9 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,8 +21,9 @@ let basketballTeam = { */ // write code here +let playerNames = basketballTeam.topPlayers.sort().join("\r\n"); ; - +console.log(playerNames ); /* EXPECTED RESULT Dennis Rodman diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..e0a9e9e5 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -23,6 +23,9 @@ let capitalCities = { */ // write code here +capitalCities.UnitedKingdom.population=8980000; +capitalCities.China.population=21500000; +capitalCities.Peru={name : "Lima",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..71182983 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -16,7 +16,7 @@ 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 @@ -24,6 +24,9 @@ let student = { exam score is above 60. - Use bracket notation to change the value of hasPassed */ +if(student.attendance>=90 && student.examScore>60){ + student["hasPassed"] = true; +} // write code here diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..c7e34a73 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"]);//the colour property is not define in car object // Example 2 function sayHelloToUser(user) { @@ -25,7 +25,7 @@ let user = { name: "Mira" }; -sayHelloToUser(user); +sayHelloToUser(user);//user object has name as a property and in sayHello function it just log firstname from user object that is not defined // Example 3 let myPet = { @@ -35,4 +35,4 @@ let myPet = { }, }; -console.log(myPet.getName()); +console.log(myPet.getName());//the object function doesn't return the value diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..25042bb0 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(`Studet name :${name}`); + }, +}; student.getName("Daniel"); From 3d21165871df307f6d9eb9037d18265b71bdfc14 Mon Sep 17 00:00:00 2001 From: leilafaez Date: Tue, 4 Oct 2022 20:24:45 +0100 Subject: [PATCH 2/3] Update mandatory folder --- 2-mandatory/1-recipes.js | 9 ++++++++- 2-mandatory/2-currency-code-lookup.js | 7 +++++++ 2-mandatory/3-shopping-list.js | 7 ++++++- 2-mandatory/4-restaurant.js | 15 ++++++++++++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..8ae1d143 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,11 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here +const Recipe ={ + title : "fish", + serves : 4, + ingredients : ["fish","rice"], +}; + + console.log(`${Recipe.title}\n Serves :${Recipe.serves}\n Ingredients:\n${(Recipe.ingredients).join("\t\n")}`); diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..0e45ba6c 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,13 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + return countryCurrencyCodes.reduce(function(arr1,arr2){ + arr1[arr2[0]]=arr2[1]; + return arr1; + }, {}); + + + } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..174fe260 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 concatPantry = (pantry.fridgeContents).concat(pantry.cupboardContents); + let absence =(recipe.ingredients).filter((e)=>!concatPantry.includes(e)); + return recipe={ + name:recipe.name, + items :absence, + }; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..96e148ab 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,7 +21,20 @@ const MENU = { let cashRegister = { // write code here -} + orderBurger: function (balance) { + if (balance >= MENU.burger) { + balance = balance - MENU.burger; + return balance; + } else return balance; + }, + + orderFalafel: function (balance) { + if (balance >= MENU.falafel) { + balance = balance - MENU.falafel; + return balance; + } else return balance; + }, +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` From 0974044fa33c2d32c17d7a0ef407a36b1049424b Mon Sep 17 00:00:00 2001 From: leilafaez Date: Tue, 4 Oct 2022 21:36:00 +0100 Subject: [PATCH 3/3] Update extra folder --- 3-extra/1-count-words.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/3-extra/1-count-words.js b/3-extra/1-count-words.js index 9d347ae5..85d55940 100644 --- a/3-extra/1-count-words.js +++ b/3-extra/1-count-words.js @@ -24,10 +24,17 @@ */ function countWords(string) { - const wordCount = {}; - - // write code here - + const wordCount = { }; + let stringArray = string.split(" "); + if (string.length != 0) { + for (let word of stringArray) { + if (word in wordCount) { + wordCount[word] = wordCount[word] + 1; + } else { + wordCount[word] = 1; + } + } + } return wordCount; }