diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..c18f24f4 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, // Boleean + 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 = "Spot"; // complete the code +let dogBreed = "Dalmatian"; // 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..b9b58113 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 = "London"; // 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..272eb263 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -19,8 +19,14 @@ let basketballTeam = { - sorts the top players in alphabetical order - console.logs the name of each player on a new line */ +let alphabetPlayers = basketballTeam.topPlayers.sort() + + + // write code here +console.log(alphabetPlayers); + /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..577bf436 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -12,7 +12,6 @@ let capitalCities = { name: "Beijing", } }; - /* Using dot notation: - Change the value of UnitedKingdom's capital city population to 8980000. @@ -21,9 +20,11 @@ let capitalCities = { - Add a name of "Lima" to Peru's capital city. - Add a population of 9750000 to Peru's capital city. */ - +1076382306 // write code here - +capitalCities.UnitedKingdom.population = 8980000; +capitalCities.China.population = 21500000; +capitalCities.Peru = {name:"Lima", population : 9750000 }; console.log(capitalCities); /* EXPECTED RESULT @@ -31,7 +32,7 @@ console.log(capitalCities); { UnitedKingdom: { name: "London", population: 8980000 }, China: { name: "Beijing", population: 21500000 }, - Peru: { name: "Lima", population: 9750000 } + Peru: { name: "Lima", population = 9750000 } } */ \ No newline at end of file diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..09ac55f0 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 code here /* - Write an "if" statement that changes the value of hasPassed to true @@ -25,7 +25,9 @@ let student = { - Use bracket notation to change the value of hasPassed */ -// write code here +if (student["attendance"] >= 90 && student["examScore"] > 60) { +student["hasPassed"] = true; +} // write code here console.log(student); diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..c74d5fe8 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -8,7 +8,7 @@ For each example, can you explain why we are seeing undefined? */ -// Example 1 +// There is no property called colour // Example 1 let car = { brand: "Ford", yearsOld: 8, @@ -16,7 +16,7 @@ let car = { console.log(car["colour"]); -// Example 2 +// the object name is just name not firstname// Example 2 function sayHelloToUser(user) { console.log(`Hello ${user.firstName}`); } @@ -27,7 +27,7 @@ let user = { sayHelloToUser(user); -// Example 3 +// the values should be returned // Example 3 let myPet = { animal: "Cat", getName: function() { diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..e2b5f2f1 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -8,10 +8,13 @@ */ let student = { - // write code here + name : "Daniel", + getName: function () { + return "Student name: " + this.name; + // write code here } - -student.getName("Daniel"); +} + console.log(student.getName("Daniel")); /* EXPECTED RESULT diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..fa10a23f 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -21,5 +21,35 @@ You should write and log at least 5 recipes */ - -// write code here \ No newline at end of file +// write code here +let recipe = { + frenchToast :{ + title: "French Toast", + servings: 6, + ingredients: ["4 large eggs", "1 cup 2% milk", "2 tablespoons sugar", "2 teaspoons vanilla extract", "1/8 teaspoon salt", "12 slices day-old sandwich bread"] + }, + homemadeSpaghettiSauce :{ + title: "Homemade Spaghetti Sauce", + servings: 12, + ingredients: ["2 pounds ground beef", "1/2 cup water", "Hot cooked spaghetti", "4 cans (6 ounces each) tomato paste", "3/4 pound bulk Italian sausage"] + }, + fruitSalad :{ + title: "Brunch Fruits Salad", + servings: 10, + ingredients: ["1 can (20 ounces) pineapple chunks", "2 large firm bananas, cut into 1/4-inch chunks", "1 cup of green grapes", "1 can (15 ounces) mandarin oranges", "1 medium red apple"] + }, + vanillaFrosting :{ + title: "Vanilla Buttercream Frosting", + servings: 5, + ingredients: ["1/2 cup butter, softened", "4-1/2 cups confectioners' sugar", "1-1/2 teaspoons vanilla extract", "5 to 6 tablespoons 2% milk"] + }, + garlicBread :{ + title: "Garlic Bread", + servings: 8, + ingredients: ["1/2 cup butter, melted", "3 to 4 garlic cloves, minced", "1 loaf (1 pound) French bread, halved lengthwise", "2 tablespoons minced fresh parsley"] + } + } + + // write code here + console.log(recipe.frenchToast); + console.log (recipe.frenchToast.ingredients) \ 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..116295c7 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -34,4 +34,4 @@ test("creates country currency code lookup", () => { NG: "NGN", MX: "MXN", }); -}); \ No newline at end of file +}); diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..4817154a 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,7 +19,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, + }; // write code here } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..9c73ed8c 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,8 +20,27 @@ const MENU = { }; let cashRegister = { - // write code here -} + orderBurger: function (balance) { + if (balance >= MENU.burger) { + let newBalance = MENU.burger - balance; + return newBalance; + } else { + return balance; + } + }, + + orderFalafel: function (balance){ + if (balance >= MENU.falafel) { + let newBalance = MENU.falafel - balance; + return newBalance; + }else { + return balance; + } + } + + } + console.log(cashRegister.orderBurger(7.00)) + // write code here /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`