Conversation
pavloPolyvoda-dev
commented
Mar 3, 2026
- DEMO LINK
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job fetching the data from the DOM and correctly calculating the total and average population! The core logic is solid.
However, this requires changes because the custom number formatting function, strFormatNum, doesn't work correctly for all cases. For example, a number like 1,007,009 is incorrectly formatted as "1,7,9". This fails a key requirement of the task.
A much more robust and simpler solution is to use the built-in Number.prototype.toLocaleString() method. This function is designed to handle thousand separators and localization correctly.
For example:
// For integers
sumPopNum.toLocaleString('en-US');
// For numbers with decimals
averagePopNum.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });You're very close! Once you fix the number formatting, this will be ready.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
src/scripts/main.js
Outdated
| return sum + Number(population); | ||
| }, 0); | ||
|
|
||
| const averagePopNum = (sumPopNum / populationArray.length).toFixed(2); |
There was a problem hiding this comment.
Using .toFixed(2) here converts the average to a string prematurely. This forces your strFormatNum function to handle both string and number inputs, which can lead to unexpected behavior due to implicit type coercion. It's better to keep values as Number types for as long as possible and handle all formatting, including setting decimal places, within the formatting function itself.
src/scripts/main.js
Outdated
| function strFormatNum(number) { | ||
| const numberItems = []; | ||
|
|
||
| let currentNumber = number; | ||
|
|
||
|
|
||
| while (currentNumber / 1000 > 0) { | ||
| if (currentNumber !== parseInt(currentNumber)) { | ||
| numberItems.unshift((currentNumber % 1000).toFixed(2)); | ||
| } else { | ||
| numberItems.unshift(currentNumber % 1000); | ||
| } | ||
|
|
||
| currentNumber = parseInt(currentNumber / 1000); | ||
| } | ||
|
|
||
| return numberItems.join(','); | ||
| } |
There was a problem hiding this comment.
This custom function for formatting numbers doesn't handle all cases correctly. For instance, a number like 1,007,009 would be formatted incorrectly as "1,7,9" because the logic doesn't pad number groups with leading zeros.
A more robust and standard approach is to use the built-in Number.prototype.toLocaleString() method, which is designed for this purpose.
For example:
// For integers
sumPopNum.toLocaleString('en-US');
// For numbers with decimals
averagePopNum.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });This would be a much simpler and more reliable solution.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work! I am approving your solution. You've successfully addressed the feedback from the previous review by implementing toLocaleString() for number formatting. The code is now clean, correct, and fully meets all the requirements of the task. Great job!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨