Conversation
JorJio-svg
commented
Mar 17, 2026
- DEMO LINK
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Good effort on this task! The overall structure is correct, but there are a few critical issues that prevent the code from working as required. This requires a few changes to address the following points:
- Incorrect Number Parsing: The
replace(',', '')method only removes the first comma from the population strings. For numbers over a million, this will causeNumber()to returnNaN. Please update this to remove all commas from the string before parsing. - Incorrect Average Calculation: The average is calculated using
totalPopulation.length. SincetotalPopulationis a number, it doesn't have a.lengthproperty, which results inNaN. You should use the length of thepopulationarray to get the correct count of countries. - Missing Number Formatting: The final total and average population values need to be formatted with thousands separators (e.g.,
3,750,552,765). ThetoLocaleString()method is perfect for this requirement.
Once these items are fixed, your solution should meet all the requirements.
✨ 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 NaN; | ||
| } | ||
|
|
||
| const num = Number(str.replace(',', '').trim()); |
There was a problem hiding this comment.
The replace(',', '') method only removes the first comma from the string. Population figures can have multiple commas (e.g., '1,427,647,786'). This will cause Number() to fail on such strings. You should replace all commas. A regular expression or replaceAll() would be a good tool for this.
src/scripts/main.js
Outdated
| const averagePopulation = totalPopulation.length | ||
| ? Math.round(totalPopulation / population.length) | ||
| : NaN; |
There was a problem hiding this comment.
totalPopulation is a number, which doesn't have a .length property, so totalPopulation.length will be undefined. This will cause your average calculation to result in NaN. You should use the length of the population array here.
src/scripts/main.js
Outdated
| const total = document.querySelector('.total-population'); | ||
|
|
||
| if (average) { | ||
| average.textContent = averagePopulation; |
There was a problem hiding this comment.
The task requires the calculated average to be displayed with a thousands separator (e.g., 1,234,567). Currently, you're displaying the raw number. Consider using toLocaleString() to format the number before assigning it to textContent.
src/scripts/main.js
Outdated
| } | ||
|
|
||
| if (total) { | ||
| total.textContent = totalPopulation; |
There was a problem hiding this comment.
Similar to the average population, the total population also needs to be formatted with a thousands separator to meet the task requirements.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this update! You have successfully addressed all the feedback from the previous review, resulting in a clean and fully functional solution. The code now correctly parses the population data, calculates the total and average, and formats the output with thousands separators as required. This submission now meets all the task's specifications, and I am happy to approve it. Keep up the great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨