add task solution - #2354
add task solution#2354VeronikaNychyporuk wants to merge 3 commits into
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The formateNumber function contains a critical bug that produces incorrect output for common values. For example, input of 1,000 returns "1,0" instead of "1,000", and 1,000,000 returns "0,1,0" instead of "1,000,000". The thousands separator formatting is an explicit requirement in the task checklist, and this logic error breaks the core functionality. The algorithm incorrectly calculates group counts using Math.ceil(String(num).length / 3) instead of properly extracting 3-digit groups from right to left. Consider using JavaScript's built-in toLocaleString() method for a reliable solution, or rewrite the logic to use num % 1000 while iterating through the number. As a minor style note, the function is named formateNumber but should be formatNumber (missing the 't').
✨ 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
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because one core requirement is not fully met: you must validate that each population string can be converted to a number before using it. Currently, parseInt is called (around line 10) without checking the result; if it yields NaN, the total and average become NaN, breaking the functionality for unexpected inputs. To fix this, after parsing, verify with Number.isFinite(parsed) or !Number.isNaN(parsed) before adding to the total, and decide whether to skip invalid entries or handle them explicitly. Everything else looks solid: you correctly collect .population spans, compute total and average, and format with toLocaleString('en-IN').
Critical issues to address:
- Add validation after parsing the number (line 10) to ensure it’s a valid number per the requirement [Make sure the string can be converted to a number]. For example, strip commas, parse with
Number(...)orparseInt(..., 10), then guard withNumber.isFinite(...)before accumulation.
Minor improvement:
- Specify radix in
parseInt(..., 10)or preferNumber(valueWithoutCommas)to avoid edge cases.
Once this validation is in place, the solution will meet the checklist and should be good to go. Keep up the good work—your use of toLocaleString('en-IN') and DOM updates is spot on.
✨ 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
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved. All requirements have been met: population data is correctly parsed from the DOM, numbers are validated using Number.isNaN(), and both total and average values are calculated and displayed with proper thousands separators via toLocaleString('en-IN'). The code is clean and follows best practices. Great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
DEMO LINK