Skip to content

Commit 785d0e9

Browse files
committed
Complete destructuring exercises 1-3
1 parent 3a422e9 commit 785d0e9

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ const personOne = {
66

77
// Update the parameter to this function to make it work.
88
// Don't change anything else.
9-
function introduceYourself(___________________________) {
9+
function introduceYourself({name, age, favouriteFood}) {
1010
console.log(
1111
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
1212
);
13-
}
14-
15-
introduceYourself(personOne);
13+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@ let hogwarts = [
7070
occupation: "Teacher",
7171
},
7272
];
73+
74+
hogwarts.forEach(({ firstName, lastName, house }) => {
75+
if (house === "Gryffindor") {
76+
console.log(`${firstName} ${lastName}`);
77+
}
78+
});

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,20 @@ let order = [
66
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
77
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
88
];
9+
10+
let grandTotal = 0;
11+
12+
console.log("QTY ITEM TOTAL");
13+
14+
order.forEach(({ itemName, quantity, unitPricePence }) => {
15+
let totalPence = quantity * unitPricePence;
16+
let totalPounds = (totalPence / 100).toFixed(2);
17+
18+
grandTotal += totalPence;
19+
20+
console.log(
21+
`${quantity} ${itemName} ${totalPounds}`
22+
);
23+
});
24+
25+
console.log(`\nTotal: ${(grandTotal / 100).toFixed(2)}`);

0 commit comments

Comments
 (0)