From 628d6d8a98716c96eae3d963df1d33e91321df66 Mon Sep 17 00:00:00 2001 From: Samunta Sunuwar <153233353+Samunta@users.noreply.github.com> Date: Mon, 7 Apr 2025 15:26:57 +0100 Subject: [PATCH 1/6] Destructuring object directly in the parameter to make the function work. Sprint1- exercise 1 --- 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..90eb4795 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 7013f267cb7614df7047d01bae65567b9e32e94f Mon Sep 17 00:00:00 2001 From: Samunta Sunuwar <153233353+Samunta@users.noreply.github.com> Date: Mon, 7 Apr 2025 15:58:15 +0100 Subject: [PATCH 2/6] Exercise 2 - Task 1 --- Sprint-1/destructuring/exercise-2/exercise.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..48465a4f 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,13 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +//Task 1 +function revelioGryffindor() { + for (const { firstName, lastName, house } of hogwarts) { + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } + } +} +revelioGryffindor(hogwarts) \ No newline at end of file From b1856d9580c140480b20213c50d71ac8cdd69565 Mon Sep 17 00:00:00 2001 From: Samunta Sunuwar <153233353+Samunta@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:07:05 +0100 Subject: [PATCH 3/6] Program to filter out teacher with Pets --- Sprint-1/destructuring/exercise-2/exercise.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 48465a4f..924b5515 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -79,4 +79,14 @@ function revelioGryffindor() { } } } -revelioGryffindor(hogwarts) \ No newline at end of file +revelioGryffindor(hogwarts) + +//Task 2 +function accioPets(){ + for (const { firstName, lastName, pet, occupation } of hogwarts) { + if (occupation === "Teacher" && pet !== null) { + console.log(`${firstName} ${lastName}`); + } + } +} +accioPets(hogwarts) \ No newline at end of file From d6c259ed30bc4a7fa0fdb14ce31d63531dba6146 Mon Sep 17 00:00:00 2001 From: Samunta Sunuwar <153233353+Samunta@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:09:31 +0100 Subject: [PATCH 4/6] Updating Literal Templates to make it more informative and friendly. --- Sprint-1/destructuring/exercise-2/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 924b5515..ce2f8c57 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -75,7 +75,7 @@ let hogwarts = [ function revelioGryffindor() { for (const { firstName, lastName, house } of hogwarts) { if (house === "Gryffindor") { - console.log(`${firstName} ${lastName}`); + console.log(`${firstName} ${lastName} is a Gryffindor`); } } } @@ -85,7 +85,7 @@ revelioGryffindor(hogwarts) function accioPets(){ for (const { firstName, lastName, pet, occupation } of hogwarts) { if (occupation === "Teacher" && pet !== null) { - console.log(`${firstName} ${lastName}`); + console.log(`${firstName} ${lastName} is a teacher who has a pet ${pet}`); } } } From 1468b7bbc8415a19b74bd028e2edf8d76af84c7d Mon Sep 17 00:00:00 2001 From: Samunta Sunuwar <153233353+Samunta@users.noreply.github.com> Date: Mon, 7 Apr 2025 17:17:15 +0100 Subject: [PATCH 5/6] Exercise 3 - Destructuring --- Sprint-1/destructuring/exercise-3/exercise.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..426af4d3 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,23 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +function receipt() { + console.log(`QTY ITEM TOTAL`); + let total = 0; + + for (const { itemName, quantity, unitPricePence } of order) { + const unitPricePounds = unitPricePence / 100; + const totalOneItem = quantity * unitPricePounds; + total += totalOneItem; + + const itemNameFormatted = itemName.padEnd(20); + const totalFormatted = totalOneItem.toFixed(2).padStart(6); + + console.log(`${quantity} ${itemNameFormatted}${totalFormatted}`); + } + + console.log(`\nTotal: ${total.toFixed(2)}`); +} + +receipt(order); \ No newline at end of file From a94b9562236889522d75c454b7f584afd91df2e0 Mon Sep 17 00:00:00 2001 From: Samunta Sunuwar <153233353+Samunta@users.noreply.github.com> Date: Sat, 19 Apr 2025 17:02:52 +0100 Subject: [PATCH 6/6] Correct paramtere for revelioGryffindor's function as per CJ's suggestion --- Sprint-1/destructuring/exercise-2/exercise.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index ce2f8c57..1367e3e9 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -72,7 +72,8 @@ let hogwarts = [ ]; //Task 1 -function revelioGryffindor() { +//added "hogwarts" as parameter following cjyuan's feedback +function revelioGryffindor(hogwarts) { for (const { firstName, lastName, house } of hogwarts) { if (house === "Gryffindor") { console.log(`${firstName} ${lastName} is a Gryffindor`);