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
6 changes: 5 additions & 1 deletion Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const personOne = {

// Update the parameter to this function to make it work.
// Don't change anything else.
function introduceYourself(___________________________) {
function introduceYourself({
name = "NO_NAME_PROVIDED",

Choose a reason for hiding this comment

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

you've added default values to the function to protect against the function being used without parameters.
thats great!

age = "NO_AGE_PROVIDED",
favouriteFood = "NO_FOOD_PROVIDED",
} = {}) {
console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
);
Expand Down
23 changes: 23 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,26 @@ let hogwarts = [
occupation: "Teacher",
},
];

const GryffindorHousePeople = (hogwarts) => {
hogwarts.forEach(
({ firstName, lastName, house }) =>
house === "Gryffindor" && console.log(`${firstName} ${lastName}`)
);
};

const teacherHasPet = (hogwarts) => {
hogwarts.forEach(
({ firstName, lastName, pet, occupation }) =>
occupation === "Teacher" && pet && console.log(`${firstName} ${lastName}`)
);
};

Choose a reason for hiding this comment

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

see what the console output is when you run both of these methods GryffindorHouse and teacherHasPet after each other.
You may want to look at formatting the output better so that when these 2 methods are run its easy to see what the answer is for question 1 and question 2 of this exercise

console.log("*****************************");
console.log("***Gryffindor House People***");
console.log("*****************************");
GryffindorHouse(hogwarts);
console.log("\n\n*****************************");
console.log("*********teacherHasPet***********");
console.log("*****************************");
teacherHasPet(hogwarts);
14 changes: 14 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,17 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

const printReceipt = (order) => {
console.log("QTY ITEM TOTAL");
let total = 0;
order.forEach(({ itemName, quantity, unitPricePence }) => {
console.log(
`${quantity}${" ".repeat(7)}${itemName}${" ".repeat(20 - itemName.length)}${String(unitPricePence / 100).padEnd(4, 0)}`

Choose a reason for hiding this comment

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

nice work on the output formatting here

);
total += unitPricePence;
});
console.log(`\nTotal: ${String(total / 100).padEnd(4, 0)}`);
};

printReceipt(order);
Loading