-
-
Notifications
You must be signed in to change notification settings - Fork 160
West Midlands | ITP-Sept-25 | Georgina Rogers | Sprint 1 | Destructuring #347
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
There was a problem hiding this comment.
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?