From 1e9297ab345d7aadaf6a13ffd51ec0aa3f2cb125 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Wed, 15 Apr 2026 18:52:19 +0100 Subject: [PATCH 1/3] Object destructuring --- Sprint-1/destructuring/exercise-1/exercise.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..d25632d5 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,8 @@ 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 55b25e577d02677deb03f5248f5b624f1ce46d57 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Wed, 15 Apr 2026 18:55:22 +0100 Subject: [PATCH 2/3] Array input and output teachers who have pets --- Sprint-1/destructuring/exercise-2/exercise.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..11d5cdab 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,21 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +// Task 1: Display names of people in Gryffindor house +console.log("=== Gryffindor Members ==="); +for (const person of hogwarts) { + const { firstName, lastName, house } = person; + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } +} + +// Task 2: Display names of teachers who have pets +console.log("\n=== Teachers with Pets ==="); +for (const person of hogwarts) { + const { firstName, lastName, occupation, pet } = person; + if (occupation === "Teacher" && pet !== null) { + console.log(`${firstName} ${lastName}`); + } +} From 9ea5a0855434186c45bb6bca3d9f6b98cd23701a Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Wed, 15 Apr 2026 18:58:32 +0100 Subject: [PATCH 3/3] Takeout order --- Sprint-1/destructuring/exercise-3/exercise.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..c4484502 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,30 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +// Column widths (matching the expected output) +const QTY_WIDTH = 8; +const ITEM_WIDTH = 20; + +// Print header +console.log(`${"QTY".padEnd(QTY_WIDTH)}${"ITEM".padEnd(ITEM_WIDTH)}TOTAL`); + +let totalOrder = 0; + +// Process each item using object destructuring +for (const { itemName, quantity, unitPricePence } of order) { + const itemTotalPence = quantity * unitPricePence; + const itemTotalPounds = (itemTotalPence / 100).toFixed(2); + + // Print the line item + console.log( + `${quantity.toString().padEnd(QTY_WIDTH)}${itemName.padEnd(ITEM_WIDTH)}${itemTotalPounds}` + ); + + // Accumulate total (parseFloat to convert string back to number) + totalOrder += parseFloat(itemTotalPounds); +} + +// Print final total (fixed to 2 decimal places) +console.log(`\nTotal: ${totalOrder.toFixed(2)}`); +