diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..426dcffd 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,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..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..165dc7d7 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -22,6 +22,9 @@ let basketballTeam = { // write code here +let topBasketballPlayer = basketballTeam.topPlayers.sort(); +topBasketballPlayer.map((x) => console.log(x)); + /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..4ee656f1 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -24,6 +24,12 @@ 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); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..1b5c1836 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 @@ -27,8 +29,17 @@ let student = { // write code here +if (student.attendance >= 90 && student.examScore >60) { + student.hasPassed = true; + console.log(student); +} + + + + + /* EXPECTED RESULT { diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..8ccdadc9 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"]); // We have not define colour yet! // Example 2 function sayHelloToUser(user) { @@ -25,7 +25,7 @@ let user = { name: "Mira" }; -sayHelloToUser(user); +sayHelloToUser(user); // we didn't define variable as firstName or we used wrongly firstName instead of name. // Example 3 let myPet = { @@ -35,4 +35,4 @@ let myPet = { }, }; -console.log(myPet.getName()); +console.log(myPet.getName()); // The function is not returning anything, we can use console.log inside of function or write return before the statement. diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..08033f62 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -7,11 +7,14 @@ - console.logs a message that says: "Student name: " followed by the name given as an argument */ -let student = { - // write code here +let student = { + // write code here + 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..497be3c4 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,37 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let recipes = { + roastBeef :{ + title : `Roast beef`, + servings: 6, + ingredients:["peppercorn" ,"dried thyme", " English mustard powder" , " 8oz topside joint of beef","celery seeds", " olive oil"] + }, + CherryAlmond :{ + title : `Cherry & almond tarts`, + servings: 12, + ingredients:["eggs" ," self-raising flour", "cherry jam" , "softened","ground almond"] + }, + RoastLamb :{ + title : `Roast lamb`, + servings: 8, + ingredients:["carrots" ,"onion", "small bunch parsley" ,"thyme leaf", "lemon"] + }, + Scampi :{ + title : `Scampi with tartare sauce`, + servings: 2, + ingredients:["cornflour" ,"sparkling water", "beer" ,"Dublin Bay prawn tails", " olive oil"] + } +} +function printOut(meals) { +console.log( recipes[meals]["title"]); +console.log("Serves: " + recipes[meals]["servings"]); +console.log(" Ingredients:" + recipes[meals]["ingredients"].map(x=> x + " \n ")); +} + +printOut("roastBeef"); +printOut("CherryAlmond"); +printOut("RoastLamb"); +printOut("Scampi"); \ 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..21b98759 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,11 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + let currencyObject ={}; +for (let currency of countryCurrencyCodes) { + currencyObject[currency[0]] = currency[1]; +} + return currencyObject; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..e6dc6346 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -10,7 +10,7 @@ The createShoppingList function should return an object with two properties: - "name" of the recipe, which is a string, - - "items", which is an arry of the missing ingredients that need to be on the shopping list + - "items", which is an array of the missing ingredients that need to be on the shopping list */ let pantry = { @@ -20,6 +20,21 @@ let pantry = { function createShoppingList(recipe) { // write code here + let shopinglist = {}; + shopinglist.name = recipe.name; + + let arrayofShopping = []; + for (item of recipe.ingredients) { + if ( + pantry.fridgeContents.indexOf(item) !== -1 || + pantry.cupboardContents.indexOf(item) !== -1 + ) { + } else { + arrayofShopping.push(item); + } + } + shopinglist.items = arrayofShopping; + return shopinglist; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..10cf4157 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,6 +21,12 @@ const MENU = { let cashRegister = { // write code here + orderBurger: function (balance) { + return balance >= MENU.burger ? balance - MENU.burger : balance; + }, + orderFalafel: function (balance) { + return balance >= MENU.falafel ? balance - MENU.falafel : balance; + } } /* ======= TESTS - DO NOT MODIFY =====