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

// - In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of the people who belong to the Gryffindor house.
// - Use object destructuring to extract the values you need out of each element in the array.

function findGryffindorMembers(array) {
let pplInGryffindor = [];

for (const character of array) {
const { firstName, lastName, house } = character;
const fullName = `${firstName} ${lastName}`;
if (house === "Gryffindor") {
pplInGryffindor.push(fullName);
}
}
return pplInGryffindor;
}
33 changes: 33 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,36 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

function printReceipt(array) {
const qty = "QTY";
const item = "ITEM";
const totals = "TOTAL";
console.log(`${qty.padEnd(10, " ")}${item.padEnd(20, " ")}${totals}`);
Comment on lines +11 to +14

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could also write

console.log(`${'QTY'.padEnd(10, " ")}${'ITEM'.padEnd(20, " ")}TOTAL`);`
// or
console.log('QTY'.padEnd(10, " ") + 'ITEM'.padEnd(20, " ") + 'TOTAL');


let totalPrice = 0;

for (const { itemName, quantity, unitPricePence } of array) {
const paddedQuantity = String(quantity).padEnd(10, " ");
const paddedItem = itemName.padEnd(20, " ");
let rowTotal = (quantity * unitPricePence) / 100;
let rowTotalDisplayed = rowTotal.toFixed(2);

console.log(`${paddedQuantity}${paddedItem}${rowTotalDisplayed}`);

totalPrice = totalPrice + rowTotal;
}
console.log("");
console.log(`Total: ${totalPrice.toFixed(2)}`);
}
printReceipt(order);
// ```
// QTY ITEM TOTAL
// 1 Hot Cakes 2.32
// 2 Apple Pie 2.78
// 1 Egg McMuffin 2.80
// 1 Sausage McMuffin 3.00
// 2 Hot Coffee 2.00
// 4 Hash Brown 1.60

// Total: 14.50
Loading