Skip to content
Closed
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}.`
);
Expand Down
12 changes: 12 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,15 @@ let hogwarts = [
occupation: "Teacher",
},
];

function displayHogwartsNames ({firstName,lastName}){
console.log(`${firstName} ${lastName}`);
}
hogwarts.forEach(displayHogwartsNames);
Copy link

Choose a reason for hiding this comment

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

You useddisplayHogwartsNames function as a callback function for the forEach method. Being able to pass a function as an argumetn is one of the Java Script's fundamental concepts. Can you name this concept in JS?


function teachersWithPets({firstName, lastName, pet, occupation}){
if (occupation==="Teacher" &&pet){
console.log(`${firstName} ${lastName} has a ${pet}`);
}
}
hogwarts.forEach(teachersWithPets);
5 changes: 5 additions & 0 deletions Sprint-1/destructuring/exercise-3/exercise.js
Copy link

Choose a reason for hiding this comment

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

Well done for using object destructuring as a parameter!
However, the printed result doesn't quite match to the expected result.

  1. missing column names: It should print out the column fields: QTY, ITEM, TOTAL in order and correct values for each column.
  2. number formatting: 232 should be 2.32
  3. missing Total: total price is missing
    Please refactor the code to match the expected result in readme.md

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];
function printReceipt({itemName, quantity, unitPricePence}){
const totalPrice= quantity * unitPricePence;
console.log(`${itemName} ${quantity} ${unitPricePence}`);
}
order.forEach(printReceipt);