Skip to content

task solved#2213

Open
JorJio-svg wants to merge 2 commits intomate-academy:masterfrom
JorJio-svg:develop
Open

task solved#2213
JorJio-svg wants to merge 2 commits intomate-academy:masterfrom
JorJio-svg:develop

Conversation

@JorJio-svg
Copy link

Copy link

@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

Good effort on this task! The overall structure is correct, but there are a few critical issues that prevent the code from working as required. This requires a few changes to address the following points:

  1. Incorrect Number Parsing: The replace(',', '') method only removes the first comma from the population strings. For numbers over a million, this will cause Number() to return NaN. Please update this to remove all commas from the string before parsing.
  2. Incorrect Average Calculation: The average is calculated using totalPopulation.length. Since totalPopulation is a number, it doesn't have a .length property, which results in NaN. You should use the length of the population array to get the correct count of countries.
  3. Missing Number Formatting: The final total and average population values need to be formatted with thousands separators (e.g., 3,750,552,765). The toLocaleString() method is perfect for this requirement.

Once these items are fixed, your solution should meet all 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

return NaN;
}

const num = Number(str.replace(',', '').trim());

Choose a reason for hiding this comment

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

The replace(',', '') method only removes the first comma from the string. Population figures can have multiple commas (e.g., '1,427,647,786'). This will cause Number() to fail on such strings. You should replace all commas. A regular expression or replaceAll() would be a good tool for this.

Comment on lines +19 to +21
const averagePopulation = totalPopulation.length
? Math.round(totalPopulation / population.length)
: NaN;

Choose a reason for hiding this comment

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

totalPopulation is a number, which doesn't have a .length property, so totalPopulation.length will be undefined. This will cause your average calculation to result in NaN. You should use the length of the population array here.

const total = document.querySelector('.total-population');

if (average) {
average.textContent = averagePopulation;

Choose a reason for hiding this comment

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

The task requires the calculated average to be displayed with a thousands separator (e.g., 1,234,567). Currently, you're displaying the raw number. Consider using toLocaleString() to format the number before assigning it to textContent.

}

if (total) {
total.textContent = totalPopulation;

Choose a reason for hiding this comment

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

Similar to the average population, the total population also needs to be formatted with a thousands separator to meet the task requirements.

Copy link

@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

Excellent work on this update! You have successfully addressed all the feedback from the previous review, resulting in a clean and fully functional solution. The code now correctly parses the population data, calculates the total and average, and formats the output with thousands separators as required. This submission now meets all the task's specifications, and I am happy to approve it. Keep up the great work!


✨ 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