diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..23e21f30 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; +let dogBreed = dog.breed; 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..9bf1890d 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]; console.log(myCapitalCity); diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 2e160dd5..ddc20960 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -20,8 +20,9 @@ let basketballTeam = { - console.logs the name of each player on a new line */ -// write code here +basketballTeam.topPlayers.sort() +.forEach(player => console.log(player)); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..db5554f7 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -22,7 +22,12 @@ let capitalCities = { - Add a population of 9750000 to Peru's capital city. */ -// 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..636b754e 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 @@ -25,7 +25,10 @@ let student = { - Use bracket notation to change the value of hasPassed */ -// 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..301d3df4 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 doesn't exist in the object, therefore expecting undefined. // Example 2 function sayHelloToUser(user) { @@ -25,7 +25,7 @@ let user = { name: "Mira" }; -sayHelloToUser(user); +sayHelloToUser(user);// FirstName property does't exist in the object, therefore expecting undefined. // Example 3 let myPet = { @@ -35,4 +35,4 @@ let myPet = { }, }; -console.log(myPet.getName()); +console.log(myPet.getName());// The getName function doesn't return anything, therefore expecting undefined. diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..d4ea6696 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -8,7 +8,9 @@ */ 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..6acd33a5 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,46 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file + const recipe1 = { + title : "Bread1", + serves : 2, + ingredients : ["Water", "Salt", "Flour"] + }; + + const recipe2 = { + title: "Bread2", + serves: 2, + ingredients: ["Water", "Salt", "Flour","Oil"], + }; + + const recipe3 = { + title: "Bread3", + serves: 2, + ingredients: ["Water", "Salt", "Gluten-free-flour"], + }; + + const recipe4 = { + title: "Bread4", + serves: 2, + ingredients: ["Water", "Salt", "Flour", "Sesame"], + }; + + const recipe5 = { + title: "Bread5", + serves: 2, + ingredients: ["Water", "Salt", "Flour", "Olive"], + }; + + const allRecipes = [recipe1, recipe2, recipe3, recipe4, recipe5]; + + allRecipes.forEach((recipe) =>{ + console.log(`Recipe: ${recipe.title}`); + console.log(`Serves: ${recipe.serves}`); + console.log("Ingredients:"); + recipe.ingredients.forEach((ingredient) => + console.log(ingredient)); + console.log("-------------"); + }); + + + diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..2082bb8b 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,9 +18,18 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here + + const countryCurrencyCodesLookup = {}; + +for(let countryCurrencyCode of countryCurrencyCodes){ + let countryCode = countryCurrencyCode[0]; + let currencyCode = countryCurrencyCode[1]; + countryCurrencyCodesLookup[countryCode] = currencyCode; +}; +return countryCurrencyCodesLookup; } + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` - To run all exercises/tests in the mandatory folder, run `npm test` diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..d6e9a0a2 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,8 +19,17 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here -} +let missingIngredients = recipe.ingredients.filter(ingredient => { + return !pantry.fridgeContents.includes(ingredient) && + !pantry.cupboardContents.includes(ingredient); + }); + + let shoppingList = { + name: recipe.name, + items: missingIngredients + }; + return shoppingList; +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js` @@ -43,11 +52,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..ab00f232 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,8 +20,22 @@ const MENU = { }; let cashRegister = { - // write code here -} + orderBurger: function(balance){ + if(balance >= MENU.burger){ + return balance - MENU.burger; + } else { + return balance; + } + + }, + orderFalafel: function(balance){ + if(balance >= MENU.falafel){ + return balance - MENU.falafel; + } else { + return balance; + } + } +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`