diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..2e01b341 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -3,10 +3,10 @@ const personOne = { age: 34, favouriteFood: "Spinach", }; - +let {name, age, favouriteFood} = personOne // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself(aboutMe){ console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..230e546b 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,20 @@ let hogwarts = [ occupation: "Teacher", }, ]; +function gryffindors(hogwartsArray) { + hogwartsArray.forEach(({ firstName, lastName, house }) => { + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } + }); +} +gryffindors(hogwarts); + +function teachersWithPets(hogwartsArray) { + hogwartsArray.forEach(({ firstName, lastName, pet, occupation }) => { + if (pet !== null && occupation === "Teacher") { + console.log(`${firstName} ${lastName}`); + } + }); +} +teachersWithPets(hogwarts); diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..705f22da 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,22 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; +function orders(orderItems) { + const header = `${"QTY".padEnd(5)}${"ITEM".padEnd(20)}${"TOTAL (£)".padStart( + 10 + )}`; + console.log(header); + orderItems.forEach(({ quantity, itemName, unitPricePence }) => { + const totalPounds = ((quantity * unitPricePence) / 100).toFixed(2); + const row = `${String(quantity).padEnd(5)}${itemName.padEnd( + 20 + )}${totalPounds.padStart(10)}`; + console.log(row); + }); + const grandTotal = orderItems.reduce((sum, { quantity, unitPricePence }) => { + return sum + quantity * unitPricePence; + }, 0); + console.log(`Total: £${(grandTotal / 100).toFixed(2)}`); +} + +orders(order);