Skip to content

London-ITP-Jan2025| Sabita Shrestha| Module-Data-Flows| feature/destructuring #169

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
7 changes: 4 additions & 3 deletions Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const personOne = {
name: "Popeye",
age: 34,
favouriteFood: "Spinach",
favoriteFood: "Spinach",
};

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

Expand Down
10 changes: 10 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,13 @@ let hogwarts = [
occupation: "Teacher",
},
];
hogwarts.forEach(({firstName, lastName, house, }) =>{

Choose a reason for hiding this comment

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

nit: It will be helpful for the person reading the output if there is a text with context before outputting the list.
i.e. Gryffindor members:

if (house === "Gryffindor")
console.log(`${firstName} ${lastName}`);
});

hogwarts.forEach(({firstName, lastName, pet, occupation}) =>{

Choose a reason for hiding this comment

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

nit: It will be helpful for the person reading the output if there is a text with context before outputting the list.
i.e. Teachers with pets:

if(occupation === "Teacher" && pet){
console.log(`${firstName} ${lastName}`);
}
});
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 printReceipt(order) {
console.log("QTY\tITEM\t\t\tTOTAL");

let totalPrice = 0;

order.forEach(({ itemName, quantity, unitPricePence }) => {
let totalItemPrice = (unitPricePence * quantity) / 100; // Convert pence to pounds
totalPrice += totalItemPrice;

// Format output for better alignment
console.log(`${quantity}\t${itemName.padEnd(25)} £${totalItemPrice.toFixed(2)}`);
});

console.log("\nTotal: £" + totalPrice.toFixed(2));

Choose a reason for hiding this comment

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

Can you align the TOTAL column header with the amount. The currency symbol is lined up underneath the 'T'.

Screenshot 2025-04-20 at 8 12 15 PM

}


printReceipt(order);