add task solution#2249
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation successfully handles parsing population data, calculating totals and averages, and formatting with thousands separators. However, requirement #2 states: "Make sure that the given string can be converted to a number and convert it to number" — this validation step is missing from your code. Currently, you directly push el.textContent.split(',').join('') without checking if Number() will return NaN. Invalid string data would silently propagate NaN through calculations, producing incorrect results. Add a validation check using isNaN() or filter invalid values before the reduce operation. Minor improvements: consider handling edge cases like zero .population elements to prevent NaN output, and adding null checks for the target DOM elements.
✨ 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
| for (const el of population) { | ||
| populationArray.push(el.textContent.split(',').join('')); | ||
| } | ||
|
|
||
| const totalPopulationEl = document.querySelector('.total-population'); | ||
| const averagePopulationEl = document.querySelector('.average-population'); | ||
|
|
||
| const total = populationArray.reduce((acc, sum) => acc + Number(sum), 0); |
There was a problem hiding this comment.
The task requires validating that string data can be converted to a number before conversion. Consider checking with isNaN() or !isNaN() before using Number(sum), or filter out invalid values before the reduce operation.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved. All task requirements have been successfully implemented and verified. The code now properly validates string-to-number conversions using isNaN() checks at lines 15-17, correctly calculates both total and average population values, updates the DOM elements with "Calculate it!" text, and formats numbers with thousands separators using toLocaleString('en-US'). The previous review's concern about missing validation has been resolved. Your implementation is complete and functional.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
DEMO LINK