Skip to content

Commit 8ff01f9

Browse files
committed
destructuring backlog
1 parent 3a422e9 commit 8ff01f9

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ const personOne = {
33
age: 34,
44
favouriteFood: "Spinach",
55
};
6-
6+
let { name, age, favouriteFood } = personOne;
77
// Update the parameter to this function to make it work.
88
// Don't change anything else.
9-
function introduceYourself(___________________________) {
9+
function introduceYourself(personOne) {
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,26 @@ let hogwarts = [
7070
occupation: "Teacher",
7171
},
7272
];
73+
function houseGryffindor(hogwarts) {
74+
for (let individualHogwarts of hogwarts) {
75+
if (individualHogwarts.house === "Gryffindor") {
76+
let { firstName, lastName } = individualHogwarts;
77+
console.log(`${firstName} ${lastName}`);
78+
}
79+
}
80+
}
81+
console.log("`````");
82+
houseGryffindor(hogwarts);
83+
console.log("`````");
84+
85+
function teacherWithPets(hogwarts) {
86+
for (let singlePerson of hogwarts) {
87+
if (singlePerson.occupation === "Teacher" && singlePerson.pet !== null) {
88+
let { firstName, lastName } = singlePerson;
89+
console.log(`${firstName} ${lastName}`);
90+
}
91+
}
92+
}
93+
console.log("`````");
94+
teacherWithPets(hogwarts);
95+
console.log("`````");

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,26 @@ let order = [
66
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
77
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
88
];
9+
console.log("QTY".padEnd(5) + "ITEM".padEnd(22) + "TOTAL");
10+
11+
let grandTotal = 0;
12+
13+
function valueProperty(order) {
14+
for (let singleOrder of order) {
15+
let { itemName, quantity, unitPricePence } = singleOrder;
16+
17+
let itemTotal = quantity * unitPricePence;
18+
grandTotal += itemTotal;
19+
20+
console.log(
21+
String(quantity).padEnd(5) +
22+
itemName.padEnd(22) +
23+
(itemTotal / 100).toFixed(2)
24+
);
25+
}
26+
27+
console.log("---------------------------");
28+
console.log("Total: " + (grandTotal / 100).toFixed(2));
29+
}
30+
31+
valueProperty(order);

0 commit comments

Comments
 (0)