diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..605b7fcb 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..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..0030f1a4 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,7 +21,9 @@ let basketballTeam = { */ // write code here +let sortedPlayers = basketballTeam.topPlayers.sort() +console.log(sortedPlayers); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..682eb15f 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..c5e6d20e 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,9 +28,13 @@ 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..9fc6ad1f 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -13,7 +13,7 @@ let car = { brand: "Ford", yearsOld: 8, }; - +// example one is undefined because the object car does not have a colour. console.log(car["colour"]); // Example 2 @@ -24,7 +24,7 @@ function sayHelloToUser(user) { let user = { name: "Mira" }; - +// example 2 is undefined because it is targeting the object and not the property within the object which has the users name. sayHelloToUser(user); // Example 3 @@ -34,5 +34,5 @@ let myPet = { "My pet's name is Fluffy"; }, }; - +// in example 3 the function is not returning anything. console.log(myPet.getName()); diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..de72c61d 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,6 +9,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..3ec2fe38 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,73 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here +let favoriteRecipe1 = { + title: "Pancakes", + servings: 4, + ingredients: [ + "eggs", + "flour", + "coconut oil", + "baking powder", + "sugar", + "milk", + ], +}; +console.log(favoriteRecipe1.title); +console.log(`Serves: ${favoriteRecipe1.servings}`); +favoriteRecipe1.ingredients.forEach((thing) => { + console.log(thing); +}); + +let favoriteRecipe2 = { + title: "Pasta", + servings: 4, + ingredients: ["pasta", "oil", "cheese", "milk", "salt"], +}; +console.log(favoriteRecipe2.title); +console.log(`Serves: ${favoriteRecipe2.servings}`); +favoriteRecipe2.ingredients.forEach((thing) => { + console.log(thing); +}); + +let favoriteRecipe3 = { + title: "Oats", + servings: 4, + ingredients: ["oats", "sugar", "cinnamon", "milk", "salt"], +}; +console.log(favoriteRecipe3.title); +console.log(`Serves: ${favoriteRecipe3.servings}`); +favoriteRecipe3.ingredients.forEach((thing) => { + console.log(thing); +}); + +let favoriteRecipe4 = { + title: "Curry", + servings: 4, + ingredients: [ + "meat", + "oil", + "onion", + "tumeric", + "salt", + "bay leaves", + "cardamon", + ], +}; +console.log(favoriteRecipe4.title); +console.log(`Serves: ${favoriteRecipe4.servings}`); +favoriteRecipe4.ingredients.forEach((thing) => { + console.log(thing); +}); + +let favoriteRecipe5 = { + title: "Potato salad", + servings: 4, + ingredients: ["potatoes", "green pepper", "onions", "mayo", "salt"], +}; +console.log(favoriteRecipe5.title); +console.log(`Serves: ${favoriteRecipe5.servings}`); +favoriteRecipe5.ingredients.forEach((thing) => { + console.log(thing); +}); diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..792cfe69 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,12 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + let countryCurrency = {}; + for (let code of countryCurrencyCodes) { + countryCurrency[code[0]] = code[1]; + } + return countryCurrency; + } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..c4d64d0c 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,6 +20,16 @@ let pantry = { function createShoppingList(recipe) { // write code here + let ingredientNeeded = recipe.ingredients.filter((ingredient) => { + return ( + !pantry.fridgeContents.includes(ingredient) && + !pantry.cupboardContents.includes(ingredient) + ); + }); + return { + name: recipe.name, + items: ingredientNeeded, + }; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..cf7dda11 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,7 +21,19 @@ const MENU = { let cashRegister = { // write code here -} + orderBurger: function (moneyLeft) { + if (moneyLeft >= MENU.burger) { + return moneyLeft - MENU.burger; + } + return moneyLeft; + }, + orderFalafel: function (moneyLeft) { + if (moneyLeft >= MENU.falafel) { + return moneyLeft - MENU.falafel; + } + return moneyLeft; + }, +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` diff --git a/3-extra/1-count-words.js b/3-extra/1-count-words.js index 9d347ae5..1b44735c 100644 --- a/3-extra/1-count-words.js +++ b/3-extra/1-count-words.js @@ -27,6 +27,18 @@ function countWords(string) { const wordCount = {}; // write code here + let arr = string.split(" "); + if (string.length != 0) { + for (let strings of arr) { + if (strings in wordCount) { + wordCount[strings] = wordCount[strings] + 1; + } else { + wordCount[strings] = 1; + } + } + } + + return wordCount; }