Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Sprint-1/destructuring/exercise-1/exercise.js
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the expected log in the console

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ const personOne = {
favouriteFood: "Spinach",
};

// Update the parameter to this function to make it work.
// Don't change anything else.
function introduceYourself(___________________________) {
// ✅ 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}.`
);
}

introduceYourself(personOne);
introduceYourself(personOne);
5 changes: 5 additions & 0 deletions Sprint-1/destructuring/exercise-2/exercise.js
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the implementation for task 2 of exercise 2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task 2 is still missing

Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ let hogwarts = [
occupation: "Teacher",
},
];

// ✅ destructuring inside loop
for (const { firstName, lastName, house, pet, occupation } of hogwarts) {
console.log(`${firstName} ${lastName} is a ${occupation} from ${house}`);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the condition again? Task 1 should only log people from Gryffindor

19 changes: 19 additions & 0 deletions Sprint-1/destructuring/exercise-3/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,22 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

console.log("QTY ITEM TOTAL");

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(
`${String(quantity).padEnd(8)}${itemName.padEnd(20)}${totalPounds}`
);
}

console.log("=".repeat(35));
console.log(`TOTAL: ${(grandTotal / 100).toFixed(2)}`);
Loading