From 1008b25830465bf51b493d3e7d157ab83e6e6acd Mon Sep 17 00:00:00 2001 From: Sarah Almadi Date: Sat, 9 May 2026 21:57:34 +0200 Subject: [PATCH 1/3] Update The Parameter --- Sprint-1/destructuring/exercise-1/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..d86bc7bf 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,7 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself({ name, age, favouriteFood }) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); From 2aec462ff220a52521f46c7fc3f9bb23a26ac5ef Mon Sep 17 00:00:00 2001 From: Sarah Almadi Date: Sat, 9 May 2026 22:24:22 +0200 Subject: [PATCH 2/3] Extract Values By Using Object Destructuring --- Sprint-1/destructuring/exercise-2/exercise.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..e75d10ec 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,19 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +//Task 1: Gryffindor members + +for (let { firstName, lastName, house } of hogwarts) { + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } +} + +//Task 2: Teachers with pets + +for (let { firstName, lastName, pet, occupation } of hogwarts) { + if (occupation === "Teacher" && pet) { + console.log(`${firstName} ${lastName}`); + } +} From 7a9d7e7bc58e391cda304082c8a2a71dbeb95579 Mon Sep 17 00:00:00 2001 From: Sarah Almadi Date: Sat, 9 May 2026 22:59:08 +0200 Subject: [PATCH 3/3] Format And Destructure The Object Inside The Loop --- Sprint-1/destructuring/exercise-3/exercise.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..9fd637ab 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,21 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; +//print out the receipt for this order +console.log("QTY ITEM TOTAL"); +//Looping with destructuring +let grandTotal = 0; +//object destructuring inside the loop +for (let { itemName, quantity, unitPricePence } of order) { + //total is the total price for that line in euros (because we divide pence by 100). + let total = (quantity * unitPricePence) / 100; + //Formatting each line + //Adding colomn names and their width + console.log( + `${String(quantity).padEnd(7)}${itemName.padEnd(20)}${total.toFixed(2)}` + ); + + grandTotal += total; +} + +console.log(`\nTotal: ${grandTotal.toFixed(2)}`);