Skip to content

add task solution#2267

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

add task solution#2267
illyaSmyk wants to merge 2 commits into
mate-academy:masterfrom
illyaSmyk:develop

Conversation

@illyaSmyk
Copy link
Copy Markdown

No description provided.

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

The implementation requires changes due to two critical issues. First, requirement #2 is not implemented - the code calls Number() on population values without first verifying they can be converted to valid numbers. If any population string is empty, contains text, or has an invalid format, Number() returns NaN, which propagates to the total and corrupts the average calculation. You must add validation using isNaN() (and optionally Number.isFinite()) before adding values to the total. Second, the task explicitly states "Change only main.js file", but the style files _fonts.scss and main.scss were modified despite this prohibition - revert those changes unless they were requested separately. The good news is the core logic for parsing population data, calculating averages with Math.floor(), and formatting numbers with toLocaleString('en-US') is working correctly. Once you add the number validation check and revert the style file changes, the implementation should fully meet the requirements.


✨ 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
let count = 0;

for (const element of elements) {
const num = Number(element.textContent.replaceAll(',', ''));
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 'Make sure that the given string can be converted to a number and convert it'. Currently, if a population value cannot be converted (e.g., empty string, text, or invalid format), Number() returns NaN, which makes total become NaN. Add a check using isNaN() before adding to the total to verify the value is valid.

Comment thread src/scripts/main.js Outdated
for (const element of elements) {
const num = Number(element.textContent.replaceAll(',', ''));

total += num;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since the validation check is being added in the loop, consider moving total and count increment inside a conditional block only when the number is valid.

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

All task requirements have been successfully implemented: population data is correctly retrieved from span.population elements, each value is validated with Number.isFinite() before processing to prevent NaN propagation, both total and average calculations work properly (with Math.floor() applied to the average), and numbers are formatted using toLocaleString('en-US') for thousands separators. Only main.js was modified as required, and the style files remain unchanged. The implementation demonstrates solid JavaScript fundamentals and handles edge cases appropriately.


✨ 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