Repository navigation
add task solution - #2386
add task solution#2386Erasvx wants to merge 2 commits into
Conversation
Erasvx
commented
Oct 28, 2026
- DEMO LINK
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution requires changes to address two critical issues that violate explicit task requirements.
Issue 1 - Missing number validation: The task explicitly requires "Make sure that the given string can be converted to a number and convert it to number." Your code calls parseFloat() directly without first validating the string is convertible. Add a check using isNaN() or Number() before parsing to ensure the input is valid.
Issue 2 - Division by zero: If the populations NodeList is empty, sum / populations.length will evaluate to NaN. Add a guard to check populations.length > 0 before calculating the average.
Both of these are blockers that prevent the code from meeting the stated requirements. Please address these issues and resubmit.
✨ 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
| populations.forEach((element) => { | ||
| const text = element.textContent.replace(/,/g, ''); | ||
|
|
||
| sum += parseFloat(text); |
There was a problem hiding this comment.
The task requires validating that the string can be converted to a number before converting. Consider adding a check with isNaN() or Number() to ensure the parsed value is valid before adding to the sum.
|
|
||
| total.textContent = sum.toLocaleString('en-US'); | ||
|
|
||
| average.textContent = (sum / populations.length).toLocaleString('en-US'); |
There was a problem hiding this comment.
If populations is empty, dividing by populations.length will result in NaN. Consider adding a check for empty populations.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved. All requirements from the task have been successfully implemented: the code retrieves population data from spans with class population, validates strings can be converted to numbers using isNaN() before parsing (lines 15-19), converts strings to numbers with parseFloat(), calculates both sum and average, and formats output with thousands separators using toLocaleString('en-US'). The critical issues from the previous review have been resolved - number validation is now in place and there's a guard against division by zero by checking populations.length > 0 before calculating the average (lines 24-28). The implementation correctly updates both span.total-population and span.average-population elements as required.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨