From c4fae32ca60ca43d18ce68db15517c9afb2c7c77 Mon Sep 17 00:00:00 2001 From: Tyler-leigh Date: Wed, 18 Nov 2026 22:14:11 +0200 Subject: [PATCH 1/7] Basic object destructuring in params of a function --- 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..90eb47951 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 d1b7b48d91075470ba1df8fec60dbfd242173587 Mon Sep 17 00:00:00 2001 From: Tyler-leigh Date: Wed, 18 Nov 2026 22:36:09 +0200 Subject: [PATCH 2/7] object destructuring with objects within array --- Sprint-1/destructuring/exercise-2/exercise.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb9..d965bc2a7 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,13 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function findGryffindor(characters) { + for ({ house, firstName, lastName } of characters) { + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } + } +} + +findGryffindor(hogwarts); From 27ceb1c4874071f7c8c633050fd5d04bcaf0f052 Mon Sep 17 00:00:00 2001 From: Tyler-leigh Date: Wed, 18 Nov 2026 22:43:05 +0200 Subject: [PATCH 3/7] object destructuring with object within array, more logic --- Sprint-1/destructuring/exercise-2/exercise.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index d965bc2a7..32a750a8c 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -78,5 +78,15 @@ function findGryffindor(characters) { } } } - +console.log("Gryffindor students:"); findGryffindor(hogwarts); + +function findTeachersWithPets(characters) { + for ({ firstName, lastName, occupation, pet } of characters) { + if (occupation === "Teacher" && pet !== null) { + console.log(`${firstName} ${lastName}`); + } + } +} +console.log("\n" + "Teachers with pets:"); +findTeachersWithPets(hogwarts); From 063faa260484a0ea6f2e40b4f365f8c62f0cd0d7 Mon Sep 17 00:00:00 2001 From: Tyler-leigh Date: Wed, 18 Nov 2026 22:46:02 +0200 Subject: [PATCH 4/7] object destructuring with object within array, more logic --- Sprint-1/destructuring/exercise-2/exercise.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 32a750a8c..8f5d996c4 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -90,3 +90,13 @@ function findTeachersWithPets(characters) { } console.log("\n" + "Teachers with pets:"); findTeachersWithPets(hogwarts); + +function findTeachersWithPets(characters) { + for ({ firstName, lastName, occupation, pet } of characters) { + if (occupation === "Teacher" && pet !== null) { + console.log(`${firstName} ${lastName}`); + } + } +} +console.log("\n" + "Teachers with pets:"); +findTeachersWithPets(hogwarts); From 2c212eb28fb01c73bde235ca444a6ed992afe5d7 Mon Sep 17 00:00:00 2001 From: Tyler-leigh Date: Wed, 18 Nov 2026 22:47:39 +0200 Subject: [PATCH 5/7] object destructuring with object within array, more logic --- Sprint-1/destructuring/exercise-2/exercise.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 8f5d996c4..32a750a8c 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -90,13 +90,3 @@ function findTeachersWithPets(characters) { } console.log("\n" + "Teachers with pets:"); findTeachersWithPets(hogwarts); - -function findTeachersWithPets(characters) { - for ({ firstName, lastName, occupation, pet } of characters) { - if (occupation === "Teacher" && pet !== null) { - console.log(`${firstName} ${lastName}`); - } - } -} -console.log("\n" + "Teachers with pets:"); -findTeachersWithPets(hogwarts); From 32ce441f086897cd2ca4712fa1dd1e7ab1169730 Mon Sep 17 00:00:00 2001 From: Tyler-leigh Date: Wed, 18 Nov 2026 23:37:18 +0200 Subject: [PATCH 6/7] feat: print itemised receipt with formatted columns and total --- Sprint-1/destructuring/exercise-3/exercise.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e4..b2955e5b1 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,32 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +function printReceipt(orderList) { + const header = "QTY".padEnd(7, " ") + "ITEM".padEnd(19, " ") + "TOTAL"; + console.log(header); + + let totalPounds = 0; + for (const { itemName, quantity, unitPricePence } of orderList) { + console.log( + `${String(quantity).padEnd(7, " ")}${String(itemName).padEnd(19, " ")}${((unitPricePence * quantity) / 100).toFixed(2)}` + ); + totalPounds += (unitPricePence * quantity) / 100; + } + console.log(`\nTotal: ${totalPounds.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 +``` +*/ From 0f1eafd4144d7997a5c6ead3d45738086e314b56 Mon Sep 17 00:00:00 2001 From: Tyler-leigh Date: Wed, 18 Nov 2026 23:38:40 +0200 Subject: [PATCH 7/7] fix: removed expected result from working file --- Sprint-1/destructuring/exercise-3/exercise.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b2955e5b1..1cb9ed7e2 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -22,16 +22,3 @@ function printReceipt(orderList) { } 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 -``` -*/