From dd9169537c5874ecdb58736cadd06f9bee45515c Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 27 Nov 2025 11:55:42 +0000 Subject: [PATCH 1/7] used destructuring parameter --- Sprint-1/destructuring/exercise-1/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..7b5dbf52 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -2,11 +2,11 @@ const personOne = { name: "Popeye", age: 34, favouriteFood: "Spinach", -}; +} // 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 40c2ff761bc25df2d481c8f0ba2e0438b25b7bb9 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 27 Nov 2025 12:46:40 +0000 Subject: [PATCH 2/7] Add destructuring example for a single object in exercise.js --- Sprint-1/destructuring/exercise-2/exercise.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..5d04e2a3 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,16 @@ let hogwarts = [ occupation: "Teacher", }, ]; +//do it for one object +// +const one={ + firstName: "Albus", + lastName: "Dumbledore", + house: "Gryffindor", + pet: "Phoenix", + occupation: "Teacher", +} +const {firstName,lastName,house}=one +console.log(firstName,lastName,house); + + From b39385bb5250590156d93f6f0d8d4766544280f7 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 27 Nov 2025 13:11:38 +0000 Subject: [PATCH 3/7] mapped through every element of hogwarts to access firstName, lastName, house --- Sprint-1/destructuring/exercise-2/exercise.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 5d04e2a3..d418dbd9 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,16 +70,9 @@ let hogwarts = [ occupation: "Teacher", }, ]; -//do it for one object -// -const one={ - firstName: "Albus", - lastName: "Dumbledore", - house: "Gryffindor", - pet: "Phoenix", - occupation: "Teacher", -} -const {firstName,lastName,house}=one -console.log(firstName,lastName,house); - +hogwarts.map(({ firstName, lastName, house }) => { + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } +}); From 63d03e8125f838f57ec22108910a29213c86dc95 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 27 Nov 2025 13:26:29 +0000 Subject: [PATCH 4/7] extracted the names of teachers with pets --- 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 d418dbd9..80f27dcf 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -76,3 +76,9 @@ hogwarts.map(({ firstName, lastName, house }) => { console.log(`${firstName} ${lastName}`); } }); + +hogwarts.map(({ occupation, pet, firstName, lastName }) => { + if (occupation === "Teacher" && pet !== null) { + console.log(`${firstName} ${lastName}`); + } +}); From b39462dabd4f08ecab97aa1dbde2f39f7d4a41e1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 27 Nov 2025 15:08:32 +0000 Subject: [PATCH 5/7] got the price for each item in pounds and pence --- Sprint-1/destructuring/exercise-3/exercise.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..9fdba3a7 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,12 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +order.map(({ itemName, quantity, unitPricePence }) => { + let totalPence = quantity * unitPricePence; + let pence = totalPence % 100; + let paddedPence = String(pence).padStart(2, "0"); + let pounds = String(totalPence).substring(0, String(pence).length - 1); + let priceInPoundsAndPence=`${pounds}.${paddedPence}` + +}); From b5b2a8ed6639f1c3851d6110b242a0366f7f125f Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 27 Nov 2025 15:12:26 +0000 Subject: [PATCH 6/7] corrected pounds calculation --- Sprint-1/destructuring/exercise-3/exercise.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index 9fdba3a7..5db411a9 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -11,7 +11,10 @@ order.map(({ itemName, quantity, unitPricePence }) => { let totalPence = quantity * unitPricePence; let pence = totalPence % 100; let paddedPence = String(pence).padStart(2, "0"); - let pounds = String(totalPence).substring(0, String(pence).length - 1); + let pounds = String(totalPence).substring(0, String(paddedPence).length - 1); let priceInPoundsAndPence=`${pounds}.${paddedPence}` + console.log(pence,priceInPoundsAndPence); + + }); From 7e6fbb989e2b6f69628a0495b9ad52a4d40f17e1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 30 Nov 2025 11:40:01 +0000 Subject: [PATCH 7/7] Refactor order mapping to use forEach and improve price calculation display --- Sprint-1/destructuring/exercise-3/exercise.js | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index 5db411a9..0edcb1b7 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -7,14 +7,28 @@ let order = [ { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; -order.map(({ itemName, quantity, unitPricePence }) => { +order.forEach(({ itemName, quantity, unitPricePence }) => { let totalPence = quantity * unitPricePence; let pence = totalPence % 100; let paddedPence = String(pence).padStart(2, "0"); - let pounds = String(totalPence).substring(0, String(paddedPence).length - 1); - let priceInPoundsAndPence=`${pounds}.${paddedPence}` - console.log(pence,priceInPoundsAndPence); - - - + let pounds = Math.floor(totalPence / 100); + let priceEachItem = `${pounds}.${paddedPence}`; + + console.log( + `${String(quantity).padEnd(7, " ")}${itemName.padEnd( + 20, + " " + )}${priceEachItem}` + ); +}); +let sumAllPence = 0; +order.forEach(({ quantity, unitPricePence }) => { + sumAllPence += quantity * unitPricePence; }); +let totalBillPence = sumAllPence % 100; +let paddedTotalBillPence = String(totalBillPence).padStart(2, "0"); +let totalBillPounds = Math.floor(sumAllPence / 100); +let totalBill = ` +Total: ${totalBillPounds}.${totalBillPence}`; + +console.log(totalBill);