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
3 changes: 2 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,8 @@ 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
18 changes: 18 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,21 @@ let hogwarts = [
occupation: "Teacher",
},
];

// Task 1: Display names of people in Gryffindor house
console.log("=== Gryffindor Members ===");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice headers this make the output easier to understand

for (const person of hogwarts) {
const { firstName, lastName, house } = person;
if (house === "Gryffindor") {
console.log(`${firstName} ${lastName}`);
}
}

// Task 2: Display names of teachers who have pets
console.log("\n=== Teachers with Pets ===");
for (const person of hogwarts) {
const { firstName, lastName, occupation, pet } = person;
if (occupation === "Teacher" && pet !== null) {
console.log(`${firstName} ${lastName}`);
}
}
27 changes: 27 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,30 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

// Column widths (matching the expected output)
const QTY_WIDTH = 8;
const ITEM_WIDTH = 20;

// Print header
console.log(`${"QTY".padEnd(QTY_WIDTH)}${"ITEM".padEnd(ITEM_WIDTH)}TOTAL`);

let totalOrder = 0;

// Process each item using object destructuring
for (const { itemName, quantity, unitPricePence } of order) {
const itemTotalPence = quantity * unitPricePence;
const itemTotalPounds = (itemTotalPence / 100).toFixed(2);

// Print the line item
console.log(
`${quantity.toString().padEnd(QTY_WIDTH)}${itemName.padEnd(ITEM_WIDTH)}${itemTotalPounds}`
);

// Accumulate total (parseFloat to convert string back to number)
totalOrder += parseFloat(itemTotalPounds);
}

// Print final total (fixed to 2 decimal places)
console.log(`\nTotal: ${totalOrder.toFixed(2)}`);

Loading