From 785d0e9f19fdaf7f6cf192b592981812996fb09e Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Sat, 28 Mar 2026 07:17:45 +0000 Subject: [PATCH 1/2] Complete destructuring exercises 1-3 --- Sprint-1/destructuring/exercise-1/exercise.js | 6 ++---- Sprint-1/destructuring/exercise-2/exercise.js | 6 ++++++ Sprint-1/destructuring/exercise-3/exercise.js | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..8c7f51df 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,10 +6,8 @@ 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}.` ); -} - -introduceYourself(personOne); +} \ No newline at end of file diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..6dcdf902 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,9 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +hogwarts.forEach(({ firstName, lastName, house }) => { + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } +}); \ No newline at end of file diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..d6f9f9fb 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 }, ]; + +let grandTotal = 0; + +console.log("QTY ITEM TOTAL"); + +order.forEach(({ itemName, quantity, unitPricePence }) => { + let totalPence = quantity * unitPricePence; + let totalPounds = (totalPence / 100).toFixed(2); + + grandTotal += totalPence; + + console.log( + `${quantity} ${itemName} ${totalPounds}` + ); +}); + +console.log(`\nTotal: ${(grandTotal / 100).toFixed(2)}`); \ No newline at end of file From 7ec0d5f363520f84e57031d259163a41dd5b0e45 Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Mon, 20 Apr 2026 18:53:21 +0100 Subject: [PATCH 2/2] fix: fixed erros on excercies --- Sprint-1/destructuring/exercise-1/exercise.js | 9 +++++---- Sprint-1/destructuring/exercise-2/exercise.js | 9 ++++----- Sprint-1/destructuring/exercise-3/exercise.js | 18 ++++++++++-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 8c7f51df..c2eb55dd 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -4,10 +4,11 @@ const personOne = { favouriteFood: "Spinach", }; -// Update the parameter to this function to make it work. -// Don't change anything else. -function introduceYourself({name, age, favouriteFood}) { +// ✅ destructuring in parameter +function introduceYourself({ name, age, favouriteFood }) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); -} \ No newline at end of file +} + +introduceYourself(personOne); \ No newline at end of file diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 6dcdf902..a67cbad2 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -71,8 +71,7 @@ let hogwarts = [ }, ]; -hogwarts.forEach(({ firstName, lastName, house }) => { - if (house === "Gryffindor") { - console.log(`${firstName} ${lastName}`); - } -}); \ No newline at end of file +// ✅ destructuring inside loop +for (const { firstName, lastName, house, pet, occupation } of hogwarts) { + console.log(`${firstName} ${lastName} is a ${occupation} from ${house}`); +} \ No newline at end of file diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index d6f9f9fb..6ebf3cb6 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -7,19 +7,21 @@ let order = [ { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; -let grandTotal = 0; - console.log("QTY ITEM TOTAL"); -order.forEach(({ itemName, quantity, unitPricePence }) => { - let totalPence = quantity * unitPricePence; - let totalPounds = (totalPence / 100).toFixed(2); +let grandTotal = 0; + +// ✅ destructuring + formatting +for (const { itemName, quantity, unitPricePence } of order) { + const totalPence = quantity * unitPricePence; + const totalPounds = (totalPence / 100).toFixed(2); grandTotal += totalPence; console.log( - `${quantity} ${itemName} ${totalPounds}` + `${String(quantity).padEnd(8)}${itemName.padEnd(20)}${totalPounds}` ); -}); +} -console.log(`\nTotal: ${(grandTotal / 100).toFixed(2)}`); \ No newline at end of file +console.log("=".repeat(35)); +console.log(`TOTAL: ${(grandTotal / 100).toFixed(2)}`); \ No newline at end of file