From 1b397d960bf8acd9f262b0091f3b3272264b3c07 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Thu, 19 Nov 2026 22:49:31 +0000 Subject: [PATCH 1/4] Update function parameter with object keys --- 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 bf4e22bae8417f8f8d3b31e7b1c6695c2a8b1a98 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Thu, 19 Nov 2026 23:33:04 +0000 Subject: [PATCH 2/4] Implement function to display name. --- Sprint-1/destructuring/exercise-2/exercise.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb9..72559dd4c 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,14 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function displayGryffindorStudents(hogwarts) { + for (const student of hogwarts) { + const { firstName, lastName, house } = student; + + if (student.house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } + } +} +displayGryffindorStudents(hogwarts); From 7b5310fc77f0a66f65025bcdfda045ba8dd36764 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Thu, 19 Nov 2026 23:44:29 +0000 Subject: [PATCH 3/4] function displayTeachersWithPets(hogwarts) { Implement function to display teachers with pets --- Sprint-1/destructuring/exercise-2/exercise.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 72559dd4c..c4cf119c8 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -75,9 +75,21 @@ function displayGryffindorStudents(hogwarts) { for (const student of hogwarts) { const { firstName, lastName, house } = student; - if (student.house === "Gryffindor") { + if (house === "Gryffindor") { console.log(`${firstName} ${lastName}`); } } } displayGryffindorStudents(hogwarts); + +function displayTeachersWithPets(hogwarts) { + for (const teacher of hogwarts) { + const { firstName, lastName, pet } = teacher; + + if (pet) { + console.log(`${firstName} ${lastName}`); + } + } +} + +displayTeachersWithPets(hogwarts); From e40e1ecf85a419e3bada5e7b65e537bdcbc3888c Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 20 Nov 2026 11:56:35 +0000 Subject: [PATCH 4/4] Implement printReceipt function --- Sprint-1/destructuring/exercise-3/exercise.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e4..a32b61ff0 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,22 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +function printReceipt(order) { + let total = 0; + + console.log("QTY".padEnd(8) + "ITEM".padEnd(20) + "TOTAL"); + + for (const item of order) { + const { itemName, quantity, unitPricePence } = item; + + const itemTotal = quantity * unitPricePence; + total += itemTotal; + + console.log( + `${String(quantity).padEnd(7)} ${itemName.padEnd(19)} ${(itemTotal / 100).toFixed(2)}` + ); + } + console.log(`\nTotal: ${(total / 100).toFixed(2)}`); +} +printReceipt(order);