From 2b2114e0ff2c0bbdb2518542a829af10b42122a5 Mon Sep 17 00:00:00 2001 From: Ahmad Hmedan Date: Fri, 12 Dec 2025 17:10:24 +0000 Subject: [PATCH 1/5] use object destructuring --- 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..9bd03156 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 14817ee51175cb5dfec4f9f44c010e977c46c360 Mon Sep 17 00:00:00 2001 From: Ahmad Hmedan Date: Fri, 12 Dec 2025 17:37:49 +0000 Subject: [PATCH 2/5] Filter the array by house:Gryffindor --- Sprint-1/destructuring/exercise-2/exercise.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..e9c4834b 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", }, ]; +function gryffindorHouse(hogwarts){ +return hogwarts.filter(({house})=>house==="Gryffindor"); +} +console.log(gryffindorHouse(hogwarts)) +//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. From 2e088c5c71ddeef2723f06afd55aeb712347cd91 Mon Sep 17 00:00:00 2001 From: Ahmad Hmedan Date: Fri, 12 Dec 2025 17:43:32 +0000 Subject: [PATCH 3/5] Task 1 has been solved --- Sprint-1/destructuring/exercise-2/exercise.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e9c4834b..cb074165 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -71,8 +71,8 @@ let hogwarts = [ }, ]; function gryffindorHouse(hogwarts){ -return hogwarts.filter(({house})=>house==="Gryffindor"); + + hogwarts.filter(({house})=>house==="Gryffindor") +.forEach(({firstName,lastName})=> + console.log(`${firstName} ${lastName}`)) } -console.log(gryffindorHouse(hogwarts)) -//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. From 002a1ef38fbfa0f475547389abd97adc9b655d52 Mon Sep 17 00:00:00 2001 From: Ahmad Hmedan Date: Fri, 12 Dec 2025 17:59:24 +0000 Subject: [PATCH 4/5] implement teacherhavepet function --- Sprint-1/destructuring/exercise-2/exercise.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index cb074165..01954d2b 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,9 +70,16 @@ let hogwarts = [ occupation: "Teacher", }, ]; -function gryffindorHouse(hogwarts){ +function gryffindorHouse(arr){ - hogwarts.filter(({house})=>house==="Gryffindor") + arr.filter(({house})=>house==="Gryffindor") .forEach(({firstName,lastName})=> console.log(`${firstName} ${lastName}`)) } + function teachersHavePet(arr){ + arr.filter(({occupation,pet})=>(occupation==="Teacher" && pet)) + .forEach(({firstName,lastName})=> console.log(`${firstName} ${lastName}`)) + } + gryffindorHouse(hogwarts); + console.log("***************************************") + teachersHavePet(hogwarts); \ No newline at end of file From 720733e263627f34cf15170b2e9bc238099b1095 Mon Sep 17 00:00:00 2001 From: Ahmad Hmedan Date: Fri, 12 Dec 2025 20:15:32 +0000 Subject: [PATCH 5/5] Impelment receipt function using destructuring and same format --- Sprint-1/destructuring/exercise-3/exercise.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..dd8dff3a 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,19 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; +function receipt(arr){ + let total=0; + const firstLine="QTY".padEnd(8)+"ITEM".padEnd(20)+"Total"; + console.log(firstLine); + + +arr.forEach(({itemName,quantity,unitPricePence})=> { + itemPrice=unitPricePence*quantity/100; + const line=String(quantity).padEnd(8)+itemName.padEnd(20)+itemPrice.toFixed(2); + console.log(line); + total+=itemPrice +}) +console.log(`\nTotal: ${total.toFixed(2)}`) +} + +receipt(order); \ No newline at end of file