From 62a3e7a1441d37d9d884445d6c02d02d38ef39b0 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 30 Nov 2026 11:37:26 +0000 Subject: [PATCH 1/5] completed exercise 1 --- Sprint-1/destructuring/exercise-1/exercise.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5cf..4a6e03ef9 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,11 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself(person) { + const name = person.name; + const age = person.age; + const favouriteFood = person.favouriteFood; + console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); From 0347099ff62386f9156b9edb048c86ebcfa554ab Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 30 Nov 2026 11:37:42 +0000 Subject: [PATCH 2/5] completed exercies-2 --- Sprint-1/destructuring/exercise-2/exercise.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb9..c30d0d5cb 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,30 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function hogwartsOnly(objects) { + let hogwartsians = ""; + for (const object of objects) + if (object.house === "Gryffindor") { + const firstName = object.firstName; + const lastName = object.lastName; + const fullName = `${firstName} ${lastName}`; + hogwartsians = hogwartsians.concat("\n", fullName); + } + return hogwartsians; +} + +function teachersHavePet(objects) { + let teachers = ""; + for (const object of objects) + if (object.pet != null && object.occupation === "Teacher") { + const firstName = object.firstName; + const lastName = object.lastName; + const fullName = `${firstName} ${lastName}`; + teachers = teachers.concat("\n", fullName); + } + return teachers; +} + +console.log(hogwartsOnly(hogwarts)); +console.log(teachersHavePet(hogwarts)); \ No newline at end of file From 8e37c04be86d2cb515ddf674908a001c6c043459 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 30 Nov 2026 12:19:05 +0000 Subject: [PATCH 3/5] completed exercise 3 and formatted documents for all exercises --- Sprint-1/destructuring/exercise-1/exercise.js | 2 +- Sprint-1/destructuring/exercise-2/exercise.js | 4 ++-- Sprint-1/destructuring/exercise-3/exercise.js | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 4a6e03ef9..598b97b8f 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -10,7 +10,7 @@ function introduceYourself(person) { const name = person.name; const age = person.age; const favouriteFood = person.favouriteFood; - + console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index c30d0d5cb..6ef2cbbbf 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -91,9 +91,9 @@ function teachersHavePet(objects) { const lastName = object.lastName; const fullName = `${firstName} ${lastName}`; teachers = teachers.concat("\n", fullName); - } + } return teachers; } console.log(hogwartsOnly(hogwarts)); -console.log(teachersHavePet(hogwarts)); \ No newline at end of file +console.log(teachersHavePet(hogwarts)); diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e4..44cb9a3eb 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,18 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +function printReceipt(items) { + let total = 0; + console.log(`${"QTY".padEnd(8, " ")}${"ITEM".padEnd(20, " ")}` + "TOTAL"); + for (const { itemName, quantity, unitPricePence } of items) { + const itemTotal = (unitPricePence * quantity) / 100; + total += itemTotal; + console.log( + `${String(quantity).padEnd(8, " ")}${itemName.padEnd(20, " ")}${itemTotal.toFixed(2)}` + ); + } + console.log(`\n Total: ${total.toFixed(2)}`); +} + +printReceipt(items); From 242b4a224ed65fbda3818378378a47df3c18f1ac Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 30 Nov 2026 22:55:14 +0000 Subject: [PATCH 4/5] rewrite in restructuring syntax --- Sprint-1/destructuring/exercise-1/exercise.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 598b97b8f..7df961131 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,12 +6,8 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(person) { - const name = person.name; - const age = person.age; - const favouriteFood = person.favouriteFood; - - console.log( +function introduceYourself({ name, age, favouriteFood }) { +console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); } From ac8d8d5f4c125e81cfe703a8d58e06fd4c40765e Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 30 Nov 2026 23:17:43 +0000 Subject: [PATCH 5/5] rewrite the function with applying destructuring syntax. And formatted documents for ex1 and ex2 --- Sprint-1/destructuring/exercise-1/exercise.js | 2 +- Sprint-1/destructuring/exercise-2/exercise.js | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 7df961131..d86bc7bf8 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -7,7 +7,7 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. function introduceYourself({ name, age, favouriteFood }) { -console.log( + console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); } diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 6ef2cbbbf..b78114e54 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -73,10 +73,8 @@ let hogwarts = [ function hogwartsOnly(objects) { let hogwartsians = ""; - for (const object of objects) - if (object.house === "Gryffindor") { - const firstName = object.firstName; - const lastName = object.lastName; + for (const { firstName, lastName, house } of objects) + if (house === "Gryffindor") { const fullName = `${firstName} ${lastName}`; hogwartsians = hogwartsians.concat("\n", fullName); } @@ -85,10 +83,8 @@ function hogwartsOnly(objects) { function teachersHavePet(objects) { let teachers = ""; - for (const object of objects) - if (object.pet != null && object.occupation === "Teacher") { - const firstName = object.firstName; - const lastName = object.lastName; + for (const { firstName, lastName, occupation, pet } of objects) + if (pet != null && occupation === "Teacher") { const fullName = `${firstName} ${lastName}`; teachers = teachers.concat("\n", fullName); }