From cfd5d0e7f2bfc91213cf42edcbe6f23eaab7887e Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Thu, 13 Aug 2026 18:13:11 +0100 Subject: [PATCH 1/4] update function parameter to use destructuring on the object that gets passed in --- 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 1ff2ac5cf..d86bc7bf8 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 10f4f5648d3f0a7ed35b9409cd0a08fe7ed8b2a9 Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Thu, 13 Aug 2026 18:38:53 +0100 Subject: [PATCH 2/4] implement function to find the people who belong to the Gryffindor house --- Sprint-1/destructuring/exercise-2/exercise.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb9..49a2a45b4 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,12 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +// - In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of the people who belong to the Gryffindor house. +// - Use object destructuring to extract the values you need out of each element in the array. + +function findGryffindorMembers(array) { + for (character of array) { + let { house } = character; + } +} From 54034a841d20fd6082a572acdb1047179daa2ac1 Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Thu, 13 Aug 2026 18:39:33 +0100 Subject: [PATCH 3/4] add return value --- Sprint-1/destructuring/exercise-2/exercise.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 49a2a45b4..bf02984f8 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -75,7 +75,14 @@ let hogwarts = [ // - Use object destructuring to extract the values you need out of each element in the array. function findGryffindorMembers(array) { - for (character of array) { - let { house } = character; + let pplInGryffindor = []; + + for (const character of array) { + const { firstName, lastName, house } = character; + const fullName = `${firstName} ${lastName}`; + if (house === "Gryffindor") { + pplInGryffindor.push(fullName); + } } + return pplInGryffindor; } From 39dda6a1a6f68ecb90cc79a6746aff6c7973d8df Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Thu, 13 Aug 2026 20:42:36 +0100 Subject: [PATCH 4/4] implement printReceipt() --- Sprint-1/destructuring/exercise-3/exercise.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e4..706d5d32d 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,36 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +function printReceipt(array) { + const qty = "QTY"; + const item = "ITEM"; + const totals = "TOTAL"; + console.log(`${qty.padEnd(10, " ")}${item.padEnd(20, " ")}${totals}`); + + let totalPrice = 0; + + for (const { itemName, quantity, unitPricePence } of array) { + const paddedQuantity = String(quantity).padEnd(10, " "); + const paddedItem = itemName.padEnd(20, " "); + let rowTotal = (quantity * unitPricePence) / 100; + let rowTotalDisplayed = rowTotal.toFixed(2); + + console.log(`${paddedQuantity}${paddedItem}${rowTotalDisplayed}`); + + totalPrice = totalPrice + rowTotal; + } + console.log(""); + console.log(`Total: ${totalPrice.toFixed(2)}`); +} +printReceipt(order); +// ``` +// QTY ITEM TOTAL +// 1 Hot Cakes 2.32 +// 2 Apple Pie 2.78 +// 1 Egg McMuffin 2.80 +// 1 Sausage McMuffin 3.00 +// 2 Hot Coffee 2.00 +// 4 Hash Brown 1.60 + +// Total: 14.50