Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const personOne = {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!
This is the way

);
Expand Down
18 changes: 18 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,21 @@ let hogwarts = [
occupation: "Teacher",
},
];

// Task 1
function belongToGryffindor({ firstName, lastName, house }) {
if (house === "Gryffindor") {
console.log(`${firstName} ${lastName}`);
}
}

// Task 2
function teachersWithPets({ firstName, lastName, occupation, pet }) {
if (occupation === "Teacher" && pet != null) {
console.log(`${firstName} ${lastName}`);
}
}

hogwarts.forEach(belongToGryffindor);

hogwarts.forEach(teachersWithPets);
12 changes: 12 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,15 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

function orderReceipt({ quantity, itemName, unitPricePence }) {
let total = ((unitPricePence * quantity) / 100).toFixed(2);
console.log(
String(quantity).padEnd(9),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. You can also do number.toString().padEnd(9) or such as most data types have a toString() method to parse that value as a string.

itemName.padEnd(18),
total.padEnd(20)
);
}

console.log("QTY".padEnd(10) + "ITEM".padEnd(20) + "TOTAL".padEnd(20));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is the goal to print out like this in the console? Or can you also use console.table() ?

order.forEach(orderReceipt);
Loading