Skip to content

Conversation

@enjoy15
Copy link

@enjoy15 enjoy15 commented Nov 29, 2025

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

  • Exercise 1-3 updated

@enjoy15 enjoy15 added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Flows The name of the module. labels Nov 29, 2025
@illicitonion illicitonion added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Dec 10, 2025
Copy link
Member

@illicitonion illicitonion left a 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");
Copy link
Member

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?

Copy link
Author

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
Copy link
Member

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.

Copy link
Author

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

Copy link
Member

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).

Copy link
Author

Choose a reason for hiding this comment

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

Comment removed.

@illicitonion illicitonion added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Dec 10, 2025
@enjoy15 enjoy15 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 10, 2025
const columnSpacing = 8;

// Print the receipt header with aligned columns
console.log("QTY".padEnd(columnSpacing) + "ITEM".padEnd(20) + "TOTAL");
Copy link
Member

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?

Copy link
Author

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
Copy link
Member

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).

@illicitonion illicitonion removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 11, 2025
@enjoy15 enjoy15 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 11, 2025
const COLUMN_SPACING = 8;
const ITEM_COLUMN_WIDTH = 20;

function formatColumn(content, width) {
Copy link
Member

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?

Copy link
Author

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 illicitonion removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 12, 2025
@enjoy15 enjoy15 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 12, 2025
Copy link
Member

@illicitonion illicitonion left a 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.

@illicitonion illicitonion removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 12, 2025
@enjoy15
Copy link
Author

enjoy15 commented Dec 12, 2025

Redundant comments removed.

@enjoy15 enjoy15 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 12, 2025
);
}

// Print the receipt header with aligned columns
Copy link
Member

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 :)

Copy link
Author

Choose a reason for hiding this comment

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

redundant comments removed

@illicitonion illicitonion added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Dec 16, 2025
Copy link
Member

@illicitonion illicitonion left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Data-Flows The name of the module. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants