-
-
Notifications
You must be signed in to change notification settings - Fork 161
Birmingham | 25-ITP-Sept | Joy Opachavalit | Sprint 1 | Feature/destructuring #335
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
Conversation
illicitonion
left a comment
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 is looking really good - I left a couple of comments to consider for how to make your code even more clean, but this is all looking great, well done!
| ]; | ||
|
|
||
| // Print the receipt header | ||
| console.log("QTY ITEM TOTAL"); |
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 works, but let's imagine we wanted to change the spacing between the columns. Right now I would need to change two bits of code - this line, and also line 23 where we say how much padding to add.
Can you think how to restructure this code so that I would only need to change one place if I wanted to change the spacing?
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.
@illicitonion I define a variable for the column spacing and use it consistently in both places. This way, if I want to change the spacing, I nly need to update the variable.
| ); | ||
| }); | ||
|
|
||
| // Log the total cost |
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.
These comments don't seem to be adding a lot of value to this code... Have a read of https://www.jackfranklin.co.uk/blog/code-comments-why-not-how/ and think if either these comments could be changed, or could be removed, or if there are any changes you could make to your code to make them unnecessary.
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.
@illicitonion Comments reviewed and amended
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.
I'm still not sure the comments are providing much value here.
console.log(\nTotal: ${totalCost.toFixed(2)}); is the last line of code. And from reading the code, it's quite clear what it's doing: printing (console.log) the total cost (totalCost), at the end (it's the last line).
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.
Comment removed.
| const columnSpacing = 8; | ||
|
|
||
| // Print the receipt header with aligned columns | ||
| console.log("QTY".padEnd(columnSpacing) + "ITEM".padEnd(20) + "TOTAL"); |
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.
You're still repeating the 20 across these lines :)
Also, rather than having two different lines of code where you need to refer to the same variable, can you think how a function could help you not even need that variable?
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.
Function added.
| ); | ||
| }); | ||
|
|
||
| // Log the total cost |
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.
I'm still not sure the comments are providing much value here.
console.log(\nTotal: ${totalCost.toFixed(2)}); is the last line of code. And from reading the code, it's quite clear what it's doing: printing (console.log) the total cost (totalCost), at the end (it's the last line).
| const COLUMN_SPACING = 8; | ||
| const ITEM_COLUMN_WIDTH = 20; | ||
|
|
||
| function formatColumn(content, width) { |
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 can be a helpful function on its own, but it doesn't solve the problem of repeating the constants at each call site.
But each line has exactly three columns with the same spacings - quantity, item, and total. So it feels like you could make a function formatColumns(quantity, item, total) which is responsible for the column widths, and then call that function twice?
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.
Refactor column formatting function for receipt alignment
illicitonion
left a comment
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.
Looks good! But unfortunately your comment problem has come back, e.g. function formatColumns is clear enough about what it does - the comment "// Function to format multiple columns" doesn't add any extra information/value here. Similarly, the "Print the total cost at the end" comment came back.
|
Redundant comments removed. |
| ); | ||
| } | ||
|
|
||
| // Print the receipt header with aligned columns |
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.
I think there are still some redundant comments you could remove here :)
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.
redundant comments removed
illicitonion
left a comment
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.
Looks great, well done!
Learners, PR Template
Self checklist
Changelist