Skip to content

Commit 7d3bb3c

Browse files
committed
GLASGOW | 26-ITP-Jan | Prakash Dcosta | Sprint 1 | Object Destructuring
1 parent 3a422e9 commit 7d3bb3c

3 files changed

Lines changed: 37 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+
/* Task 1 */
74+
function houseGryffindorNames(array) {
75+
array.forEach(({ firstName, lastName, house }) => {
76+
if (house === "Gryffindor") {
77+
console.log(firstName, lastName);
78+
}
79+
});
80+
}
81+
houseGryffindorNames(hogwarts);
82+
83+
/* Task 2 */
84+
function teachersPetNames(array) {
85+
array.forEach(({ firstName, lastName, occupation, pet }) => {
86+
if (occupation === "Teacher" && pet !== null) {
87+
console.log(firstName, lastName);
88+
}
89+
});
90+
}
91+
teachersPetNames(hogwarts);

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+
function takeOutOrder(order) {
11+
let totalSum = 0;
12+
13+
console.log("OTY ITEM TOTAL");
14+
order.forEach(({ quantity, itemName, unitPricePence }) => {
15+
const itemTotal = (quantity * unitPricePence) / 100;
16+
totalSum += itemTotal;
17+
18+
console.log(
19+
`${quantity} ${itemName.padEnd(18)} ${itemTotal.toFixed(2)}`
20+
);
21+
});
22+
23+
console.log(`\nTotal: ${totalSum.toFixed(2)}`);
24+
}
25+
takeOutOrder(order);

0 commit comments

Comments
 (0)