Skip to content

Commit 2ea2b47

Browse files
committed
Implement using object destructuring, Gryffindor student filter, teachers-with-pets filter, and formatted takeout receipt using object destructuring
1 parent 050beed commit 2ea2b47

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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
);

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,22 @@ let hogwarts = [
7070
occupation: "Teacher",
7171
},
7272
];
73+
function getGryffindorStudents(hogwarts) {
74+
for (const { firstName, lastName, house } of hogwarts) {
75+
if (house === "Gryffindor") {
76+
console.log(`${firstName} ${lastName}`);
77+
}
78+
}
79+
}
80+
getGryffindorStudents(hogwarts);
81+
82+
83+
function getTeachersWithPets(hogwarts) {
84+
for (const { firstName, lastName, occupation, pet } of hogwarts) {
85+
if (occupation === "Teacher" && pet) {
86+
console.log(`${firstName} ${lastName}`);
87+
}
88+
}
89+
}
90+
91+
getTeachersWithPets(hogwarts);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@ let order = [
66
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
77
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
88
];
9+
console.log("QTY ITEM TOTAL");
10+
let overallTotal = 0;
11+
for (const{ itemName, quantity, unitPricePence } of order) {
12+
const total = quantity * unitPricePence;
13+
overallTotal += total;
14+
console.log(
15+
`${quantity.toString().padStart(2)} ${itemName.padEnd(30)} £${(total / 100).toFixed(2)}`
16+
);
17+
}
18+
console.log(`\nTotal: £${(overallTotal/100).toFixed(2)}`);
19+

0 commit comments

Comments
 (0)