From b063f16ab48de82401683e0ca1df221be41d7845 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Sun, 5 Apr 2026 13:59:18 +0100 Subject: [PATCH 1/4] Complete exercise-1 basic destructuring --- 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 5eb29ba8935e2f385d1f3918ee073e297ed37565 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Sun, 5 Apr 2026 14:00:48 +0100 Subject: [PATCH 2/4] Complete exercise-2 filter hogwarts data with destructuring --- Sprint-1/destructuring/exercise-2/exercise.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..3d33ca89 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,16 @@ let hogwarts = [ occupation: "Teacher", }, ]; +hogwarts.forEach(({ firstName, lastName, house }) => { + if (house === "Gryffindor") { + console.log(firstName + " " + lastName); + } +}); + +hogwarts.forEach((person) => { + const { firstName, lastName, occupation, pet } = person; + + if (occupation === "Teacher" && pet !== null) { + console.log(firstName + " " + lastName); + } +}); From eeefda373b0df32f642720f3212d21e5a09a6e08 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Sun, 5 Apr 2026 14:02:47 +0100 Subject: [PATCH 3/4] Complete exercise-3 print order receipt with destructuring --- Sprint-1/destructuring/exercise-3/exercise.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..13c7629a 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,20 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; +console.log("QTY ITEM TOTAL"); + +let grandTotal = 0; + +order.forEach((item) => { + const { itemName, quantity, unitPricePence } = item; + + const totalPrice = (unitPricePence * quantity) / 100; + + grandTotal += totalPrice; + + console.log( + `${quantity}\t${itemName.padEnd(18, " ")}${totalPrice.toFixed(2)}` + ); +}); + +console.log(`\nTotal: ${grandTotal.toFixed(2)}`); From 0cf4fad5d2e3c3ff6fcf66d5b71eadd2457b6e12 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Fri, 10 Apr 2026 16:34:57 +0100 Subject: [PATCH 4/4] fixed the console output formatting --- Sprint-1/destructuring/exercise-3/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index 13c7629a..2b63fbe1 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -1,12 +1,12 @@ let order = [ - { itemName: "Hot cakes", quantity: 1, unitPricePence: 232 }, + { itemName: "Hot Cakes", quantity: 1, unitPricePence: 232 }, { itemName: "Apple Pie", quantity: 2, unitPricePence: 139 }, { itemName: "Egg McMuffin", quantity: 1, unitPricePence: 280 }, { itemName: "Sausage McMuffin", quantity: 1, unitPricePence: 300 }, { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; -console.log("QTY ITEM TOTAL"); +console.log("QTY ITEM TOTAL"); let grandTotal = 0; @@ -18,7 +18,7 @@ order.forEach((item) => { grandTotal += totalPrice; console.log( - `${quantity}\t${itemName.padEnd(18, " ")}${totalPrice.toFixed(2)}` + `${String(quantity).padEnd(8, " ")}${itemName.padEnd(18, " ")}${totalPrice.toFixed(2).padStart(6, " ")}` ); });