Skip to content

ITP_LONDON | PRISCILLA_EMEBO |Module-Data-Flows | Array destructuring #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
4 changes: 3 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,9 @@ 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
14 changes: 14 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,17 @@ let hogwarts = [
occupation: "Teacher",
},
];

console.log("Gryffindor Members:");
hogwarts.forEach(({ firstName, lastName, house }) => {
if (house === "Gryffindor") {
console.log(`${firstName} ${lastName}`);
}
});

console.log("\nTeachers with Pets:");
hogwarts.forEach(({ firstName, lastName, pet, occupation }) => {
if (occupation === "Teacher" && pet) {
console.log(`${firstName} ${lastName}`);
}
});
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 },
];

console.log("QTY ITEM TOTAL");

let total = 0;

order.forEach(({ itemName, quantity, unitPricePence }) => {
let lineTotal = (quantity * unitPricePence) / 100;
total += lineTotal;
console.log(
`${String(quantity).padEnd(8)}${itemName.padEnd(20)}${lineTotal.toFixed(2)}`
Copy link

Choose a reason for hiding this comment

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

How would you modify this statement to align the value of lineTotal when its value is 10.00 or more?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the review.
I will use padStart to align it

);
});

console.log(`\nTotal: ${total.toFixed(2)}`);