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
11 changes: 11 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,14 @@ let hogwarts = [
occupation: "Teacher",
},
];

function getGryffindors(arr) {
let Gryffindors = []
for (let person of arr) {
if (person["house"] === "Gryffindor") {
Gryffindors.push(`${person["firstName"]} ${person.lastName}`);
}
}
return Gryffindors;

Choose a reason for hiding this comment

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

This solution returns the Gryffindors array, which is good. However, the exercise asks that you return the first and last names. This function will only return the names in an array, like so: [“Harry Potter”, “Ron Weasley”…], you would want to convert the contents of the array to individual strings. How do you reckon you can achieve this?

}
console.log(getGryffindors(hogwarts));
21 changes: 21 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,24 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

function getReceipt(order) {
let total = 0;
let receiptLines = ["QTY ITEM TOTAL"];

Choose a reason for hiding this comment

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

Please talk to me about the spacing here? Item and Total appear to be a single string “Item Total” with loads of spacing in the array definition.

Copy link
Author

Choose a reason for hiding this comment

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

I made the spacing in order for the headings to align with the table below when it prints in the terminal. Is there a better way to do this?

let itemLines = order.map(({ itemName, quantity, unitPricePence }) => {
const itemTotal = quantity * unitPricePence;
total += itemTotal;
const priceInPounds = (itemTotal / 100).toFixed(2);

const quantityCol = String(quantity).padEnd(3, ' ');
const itemCol = itemName.padEnd(20, ' ');
const priceCol = `${priceInPounds}`.padStart(6, ' ');

return `${quantityCol} ${itemCol} ${priceCol}`;
});
receiptLines = receiptLines.concat(itemLines);
receiptLines.push("");
receiptLines.push(`TOTAL: ${(total / 100).toFixed(2)}`);
return receiptLines.join('\n');
}
console.log(getReceipt(order));

Choose a reason for hiding this comment

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

The exercise also requires that you log each item and the total cost of the order. I don’t believe you have done that in your solution here. Do you want to revisit the instructions from the exercise?

Copy link
Author

Choose a reason for hiding this comment

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

For me the table prints successfully in the terminal and looks exactly as in the instructions of the exercise

Copy link
Author

Choose a reason for hiding this comment

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

When logging the order, all items print with the quantity and price, do i need to log them in a different way, or one by one?