diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5cf..ae07cd873 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -5,11 +5,12 @@ const personOne = { }; // Update the parameter to this function to make it work. +let { name, age, favouriteFood } = personOne; // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself(personOne) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); } -introduceYourself(personOne); +console.log(introduceYourself(personOne)); diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb9..53468171f 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,18 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +// display the names of the people who belong to the Gryffindor house +hogwarts.forEach(({ firstName, lastName, house }) => { + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } +}); + +// display the names of the teachers who have pets + +hogwarts.forEach(({ firstName, lastName, occupation, pet }) => { + if (occupation === "Teacher" && pet !== null) { + console.log(`${firstName} ${lastName}`); + } +}); diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e4..11dd6defd 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,11 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; +console.log("QTY ITEM TOTAL"); +let basketTotal = 0; +order.forEach(({ itemName, quantity, unitPricePence }) => { + itemTotal = quantity * unitPricePence; + basketTotal += itemTotal; + console.log(`${quantity} ${itemName} ${itemTotal}`); +}); +console.log(`\nTotal: ${(basketTotal / 100).toFixed(2)} `);