Skip to content

add task solution - #2386

Open
Erasvx wants to merge 2 commits into
mate-academy:masterfrom
Erasvx:develop
Open

Erasvx wants to merge 2 commits into
mate-academy:masterfrom
Erasvx:develop

Conversation

@Erasvx

@Erasvx Erasvx commented Oct 28, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

  1. Rate AI review example ↩

  2. Re-request AI review example ↩

  3. Add AI review comments example ↩

Comment thread src/scripts/main.js Outdated
populations.forEach((element) => {
const text = element.textContent.replace(/,/g, '');

sum += parseFloat(text);

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 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.

Comment thread src/scripts/main.js Outdated

total.textContent = sum.toLocaleString('en-US');

average.textContent = (sum / populations.length).toLocaleString('en-US');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If populations is empty, dividing by populations.length will result in NaN. Consider adding a check for empty populations.

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

Copy link
Copy Markdown

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

Footnotes

  1. Rate AI review example ↩

This branch has not been deployed

No deployments
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