Skip to content

add task solution#2249

Closed
zubchenko-maksym wants to merge 2 commits into
mate-academy:masterfrom
zubchenko-maksym:develop
Closed

add task solution#2249
zubchenko-maksym wants to merge 2 commits into
mate-academy:masterfrom
zubchenko-maksym:develop

Conversation

@zubchenko-maksym
Copy link
Copy Markdown

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/scripts/main.js Outdated
Comment on lines +6 to +13
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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants