From a3b79c62e465d77dd847dbf7933bd771e3ac68cf Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 29 Jul 2026 16:43:32 +0100 Subject: [PATCH 1/5] destructured the personOne object properties --- 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..0fe0c0c7 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -1,9 +1,10 @@ + const personOne = { name: "Popeye", age: 34, favouriteFood: "Spinach", }; - + let {name,age,favouriteFood} = personOne; // Update the parameter to this function to make it work. // Don't change anything else. function introduceYourself(___________________________) { From 4afdcdefba1b3ab906e15909379ebd12b18d7748 Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 29 Jul 2026 17:34:49 +0100 Subject: [PATCH 2/5] Wrote a function using destructing to filter those in Gryffindor house --- Sprint-1/destructuring/exercise-2/exercise.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..a6f9a0ef 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,20 @@ let hogwarts = [ occupation: "Teacher", }, ]; + + +function gryffindorOccupiers(obj) { + const result = []; + + for (let person of obj) { + const { firstName, lastName, house } = person; + + if (house === "Gryffindor") { + result.push(`${firstName} ${lastName}`); + } + } + + return result; +} + +console.log(gryffindorOccupiers(hogwarts)); From 46358af6695ec3f6a75860cef85524c3e28777b8 Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 29 Jul 2026 17:48:50 +0100 Subject: [PATCH 3/5] Wrote a function for Teachers with pet --- Sprint-1/destructuring/exercise-2/exercise.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index a6f9a0ef..dcad4cbc 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -87,3 +87,23 @@ function gryffindorOccupiers(obj) { } console.log(gryffindorOccupiers(hogwarts)); + + +// task 2 + +function teachersWithPets(hogwarts) { + const result = []; + + for (let person of hogwarts) { + const { firstName, lastName, occupation, pet } = person; + + if (occupation === "Teacher" && pet) { + result.push(`${firstName} ${lastName}`); + } + } + + return result; +} + +console.log(teachersWithPets(hogwarts)); + From 740f70646d5baf62722310a5c530990ab5b486f3 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 30 Jul 2026 10:40:36 +0100 Subject: [PATCH 4/5] Print the header --- Sprint-1/destructuring/exercise-3/exercise.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..c38aac44 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,6 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + + +console.log("QTY ITEM TOTAL"); \ No newline at end of file From 29bc8c03a9870f4467bb2a50f616a3d9d2303b8e Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 30 Jul 2026 10:50:16 +0100 Subject: [PATCH 5/5] Format each line and console out --- Sprint-1/destructuring/exercise-3/exercise.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index c38aac44..55eeedc4 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -8,4 +8,22 @@ let order = [ ]; -console.log("QTY ITEM TOTAL"); \ No newline at end of file +console.log("QTY ITEM TOTAL"); + +let grandTotal = 0; + +for (let item of order) { + // Object destructuring + const { itemName, quantity, unitPricePence } = item; + const total = (unitPricePence / 100) * quantity; + grandTotal += total; // the price is in pence so divide by 100 to get pounce equivalent, + + // Format each line + const qtyStr = String(quantity).padEnd(7); + const itemStr = itemName.padEnd(20); + const totalStr = total.toFixed(2); + + console.log(`${qtyStr}${itemStr}${totalStr}`); +} + +console.log(`\nTotal: ${grandTotal.toFixed(2)}`); \ No newline at end of file