Skip to content

Commit 7ec0d5f

Browse files
committed
fix: fixed erros on excercies
1 parent 785d0e9 commit 7ec0d5f

3 files changed

Lines changed: 19 additions & 17 deletions

File tree

Sprint-1/destructuring/exercise-1/exercise.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ const personOne = {
44
favouriteFood: "Spinach",
55
};
66

7-
// Update the parameter to this function to make it work.
8-
// Don't change anything else.
9-
function introduceYourself({name, age, favouriteFood}) {
7+
// ✅ destructuring in parameter
8+
function introduceYourself({ name, age, favouriteFood }) {
109
console.log(
1110
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
1211
);
13-
}
12+
}
13+
14+
introduceYourself(personOne);

Sprint-1/destructuring/exercise-2/exercise.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ let hogwarts = [
7171
},
7272
];
7373

74-
hogwarts.forEach(({ firstName, lastName, house }) => {
75-
if (house === "Gryffindor") {
76-
console.log(`${firstName} ${lastName}`);
77-
}
78-
});
74+
// ✅ destructuring inside loop
75+
for (const { firstName, lastName, house, pet, occupation } of hogwarts) {
76+
console.log(`${firstName} ${lastName} is a ${occupation} from ${house}`);
77+
}

Sprint-1/destructuring/exercise-3/exercise.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ let order = [
77
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
88
];
99

10-
let grandTotal = 0;
11-
1210
console.log("QTY ITEM TOTAL");
1311

14-
order.forEach(({ itemName, quantity, unitPricePence }) => {
15-
let totalPence = quantity * unitPricePence;
16-
let totalPounds = (totalPence / 100).toFixed(2);
12+
let grandTotal = 0;
13+
14+
// ✅ destructuring + formatting
15+
for (const { itemName, quantity, unitPricePence } of order) {
16+
const totalPence = quantity * unitPricePence;
17+
const totalPounds = (totalPence / 100).toFixed(2);
1718

1819
grandTotal += totalPence;
1920

2021
console.log(
21-
`${quantity} ${itemName} ${totalPounds}`
22+
`${String(quantity).padEnd(8)}${itemName.padEnd(20)}${totalPounds}`
2223
);
23-
});
24+
}
2425

25-
console.log(`\nTotal: ${(grandTotal / 100).toFixed(2)}`);
26+
console.log("=".repeat(35));
27+
console.log(`TOTAL: ${(grandTotal / 100).toFixed(2)}`);

0 commit comments

Comments
 (0)