From d66b173109a79d34284a605067e7d754b53d46af Mon Sep 17 00:00:00 2001 From: Tomislav Dukez Date: Sat, 8 Aug 2026 06:44:18 +0100 Subject: [PATCH 1/7] add exercise 1 solution --- 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 64feec01f60d574e6cdac086bd07af2347330a7c Mon Sep 17 00:00:00 2001 From: Tomislav Dukez Date: Sat, 8 Aug 2026 06:52:21 +0100 Subject: [PATCH 2/7] add exercise 2 task 1 solution --- Sprint-1/destructuring/exercise-2/exercise.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..a5e79d7f 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,15 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +// TODO: Task 1 + +// 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. + +const gryffindor = hogwarts.filter(({ house }) => house === "Gryffindor"); + +console.log( + gryffindor.map(({ firstName, lastName }) => `${firstName} ${lastName}`) +); From ef4a43edc8f878a0e7bd9f012f1cc63f175935f0 Mon Sep 17 00:00:00 2001 From: Tomislav Dukez Date: Sat, 8 Aug 2026 06:54:02 +0100 Subject: [PATCH 3/7] add exercise 2 task 2 solution --- Sprint-1/destructuring/exercise-2/exercise.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index a5e79d7f..6281581c 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -82,3 +82,15 @@ const gryffindor = hogwarts.filter(({ house }) => house === "Gryffindor"); console.log( gryffindor.map(({ firstName, lastName }) => `${firstName} ${lastName}`) ); + +// Task 2 +// In exercise.js write a program that will take the hogwarts array as input and display the names of teachers who have pets. +// Use object destructuring to extract the values you need out of each element in the array. + +const teachersWithPets = hogwarts.filter(({ occupation, pet }) => { + return occupation === "Teacher" && pet; +}); + +console.log( + teachersWithPets.map(({ firstName, lastName }) => `${firstName} ${lastName}`) +); From 5c4b1d33f5bad77ea84f60cdc62176b407ed00fd Mon Sep 17 00:00:00 2001 From: Tomislav Dukez Date: Sat, 8 Aug 2026 07:05:31 +0100 Subject: [PATCH 4/7] add exercies 3 solution --- Sprint-1/destructuring/exercise-2/exercise.js | 22 +++++++++++----- Sprint-1/destructuring/exercise-3/exercise.js | 26 +++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 6281581c..e86bf7a3 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -71,7 +71,7 @@ let hogwarts = [ }, ]; -// TODO: Task 1 +// Task 1 // 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. @@ -79,18 +79,26 @@ let hogwarts = [ const gryffindor = hogwarts.filter(({ house }) => house === "Gryffindor"); -console.log( - gryffindor.map(({ firstName, lastName }) => `${firstName} ${lastName}`) -); +console.log("Hogwarts people in Gryffindor"); +for (const person of gryffindor.map( + ({ firstName, lastName }) => `${firstName} ${lastName}` +)) { + console.log(person); +} + +console.log("\n"); // Task 2 // In exercise.js write a program that will take the hogwarts array as input and display the names of teachers who have pets. // Use object destructuring to extract the values you need out of each element in the array. +console.log("Hogwarts teachers with pets"); const teachersWithPets = hogwarts.filter(({ occupation, pet }) => { return occupation === "Teacher" && pet; }); -console.log( - teachersWithPets.map(({ firstName, lastName }) => `${firstName} ${lastName}`) -); +for (const person of teachersWithPets.map( + ({ firstName, lastName }) => `${firstName} ${lastName}` +)) { + console.log(person); +} diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..d7dd00c5 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,29 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +// TODO: +// In exercise.js write a program that will take the `order` array as input and print out a receipt for the order. +// Log each individual item to the console. +// Log the total cost of the order to the console. +// Use object destructuring to access the values you need from each item. +// Pay attention to the exact formatting of the expected result. + +// Expected result + +// 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 + +console.log("QTY, ITEM, TOTAL"); +for (const { itemName, quantity, unitPricePence } of order) { + console.log( + `${quantity} ${itemName} ${((quantity * unitPricePence) / 100).toFixed(2)}` + ); +} From 565bf6406033abc8e8c3956a62fe36d842566155 Mon Sep 17 00:00:00 2001 From: Tomislav Dukez Date: Sat, 8 Aug 2026 13:42:58 +0100 Subject: [PATCH 5/7] add total output and calculation --- Sprint-1/destructuring/exercise-3/exercise.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index d7dd00c5..6d247107 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -7,7 +7,6 @@ let order = [ { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; -// TODO: // In exercise.js write a program that will take the `order` array as input and print out a receipt for the order. // Log each individual item to the console. // Log the total cost of the order to the console. @@ -26,9 +25,14 @@ let order = [ // Total: 14.50 +let total = 0; console.log("QTY, ITEM, TOTAL"); for (const { itemName, quantity, unitPricePence } of order) { + const itemTotal = quantity * unitPricePence / 100 + total += itemTotal; console.log( - `${quantity} ${itemName} ${((quantity * unitPricePence) / 100).toFixed(2)}` + `${quantity} ${itemName} ${(itemTotal).toFixed(2)}` ); } + +console.log(`\nTotal: ${(total).toFixed(2)}`); From 1b0af9ef7fb6ffebc0aa2c8aad3bba7405af8281 Mon Sep 17 00:00:00 2001 From: Tomislav Dukez Date: Sat, 8 Aug 2026 13:46:18 +0100 Subject: [PATCH 6/7] fix remove unecessary map --- Sprint-1/destructuring/exercise-2/exercise.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e86bf7a3..98ea1acb 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -97,8 +97,6 @@ const teachersWithPets = hogwarts.filter(({ occupation, pet }) => { return occupation === "Teacher" && pet; }); -for (const person of teachersWithPets.map( - ({ firstName, lastName }) => `${firstName} ${lastName}` -)) { - console.log(person); -} +for (const person of teachersWithPets) { + console.log(`${person.firstName} ${person.lastName}`) +}; From 86d5fd7441e9654a642ad9e6eb3a3135042e11d2 Mon Sep 17 00:00:00 2001 From: Tomislav Dukez Date: Sat, 8 Aug 2026 14:27:16 +0100 Subject: [PATCH 7/7] fix refactor with destructuring loop --- Sprint-1/destructuring/exercise-2/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 98ea1acb..52e6c723 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -97,6 +97,6 @@ const teachersWithPets = hogwarts.filter(({ occupation, pet }) => { return occupation === "Teacher" && pet; }); -for (const person of teachersWithPets) { - console.log(`${person.firstName} ${person.lastName}`) -}; +for (const { firstName, lastName } of teachersWithPets) { + console.log(`${firstName} ${lastName}`); +}; \ No newline at end of file