Conversation
Nika-Andriy
commented
Jan 22, 2026
- DEMO LINK
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job implementing the core logic to calculate and display the population data! The formatting works well. However, I'm requesting a couple of changes to make your code more robust by handling some important edge cases.
First, the code doesn't validate the parsed population value. If an element's text is not a valid number, parseInt will result in NaN, breaking the calculations. Please add a check to ensure you only add valid numbers to your total, as per requirement #2.
Second, if no population elements are found, the code attempts to divide by zero when calculating the average, which also results in NaN. Please add a check to prevent this, for instance, by ensuring the count of elements is greater than zero before you perform the division.
I also noticed a minor typo in a function name: toCurrectFormat should be toCorrectFormat. Addressing these points will make your solution complete!
✨ 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
| let count = 0; | ||
|
|
||
| populationArray.forEach((element) => { | ||
| const population = parseInt(element.textContent.replace(/,/g, ''), 10); |
There was a problem hiding this comment.
Good job parsing the number. However, what happens if element.textContent is not a valid number (e.g., an empty string or just text)? parseInt would return NaN, which would make your total and average also NaN. Requirement #2 asks you to make sure the string can be converted. You could add a check to handle cases where population is not a valid number.
src/scripts/main.js
Outdated
| count++; | ||
| }); | ||
|
|
||
| const average = Math.round(total / count); |
There was a problem hiding this comment.
This calculation works well, but consider what happens if populationArray is empty. In that case, count would be 0, and total / count would result in NaN. It's good practice to guard against division by zero.
src/scripts/main.js
Outdated
| document.querySelector('.average-population').textContent = | ||
| toCurrectFormat(average); | ||
|
|
||
| function toCurrectFormat(number) { |
There was a problem hiding this comment.
There's a small typo in the function name here. It looks like it should be toCorrectFormat.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work! You've successfully addressed all the feedback from the previous review, resulting in a much more robust solution. The code now gracefully handles cases with invalid numbers and prevents division by zero, which is great to see. Your implementation now meets all the requirements perfectly. I am happy to approve these changes.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨