Skip to content
9 changes: 5 additions & 4 deletions Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const personOne = {
name: "Popeye",
firstName: "Popeye",
age: 34,
favouriteFood: "Spinach",
};

let { firstName, age, favouriteFood } = personOne;
// Update the parameter to this function to make it work.
// Don't change anything else.
function introduceYourself(___________________________) {
function introduceYourself() {
console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
`Hello, my name is ${firstName}. I am ${age} years old and my favourite food is ${favouriteFood}.`
);
}

introduceYourself(personOne);
console.log(introduceYourself(personOne));
24 changes: 24 additions & 0 deletions Sprint-1/destructuring/exercise-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,27 @@ let hogwarts = [
occupation: "Teacher",
},
];
function gryffindorforStudent() {
let allStudents = "";
for (let student of hogwarts) {
let { firstName, lastName, house, pet, occupation } = student;
if (house === "Gryffindor") {
allStudents += `${firstName} ${lastName}\n`;
}
}
return allStudents;
}

function teacherWithPet() {
let allTeachers = "";
for (const person of hogwarts) {
let { firstName, lastName, pet, occupation } = person;
if (occupation === "Teacher" && pet !== null) {
allTeachers += `${firstName} ${lastName}\n`;
}
}
return allTeachers;
}

console.log(teacherWithPet(hogwarts));
console.log(gryffindorforStudent(hogwarts));
19 changes: 19 additions & 0 deletions Sprint-1/destructuring/exercise-3/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,22 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

function receipt(order) {
let totalPrice = 0;

console.log("QTY".padEnd(10) + "Item".padEnd(20) + "TOTAL");
for (const item of order) {
let { itemName, quantity, unitPricePence } = item;
let pricePerQuantity = quantity * unitPricePence;
console.log(
String(quantity).padEnd(10) +
itemName.padEnd(20) +
(pricePerQuantity / 100).toFixed(2)
);
totalPrice += pricePerQuantity;
}
totalPrice = (totalPrice / 100).toFixed(2);
}

console.log(receipt(order));