Skip to content

Solution - #2392

Open
serg121192 wants to merge 1 commit into
mate-academy:masterfrom
serg121192:develop
Open

serg121192 wants to merge 1 commit into
mate-academy:masterfrom
serg121192:develop

Conversation

@serg121192

Copy link
Copy Markdown

No description provided.

@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. The code correctly implements all required functionality: it retrieves population data from span.population elements, converts strings to numbers, calculates total and average population, and formats the results with thousands separators using Intl.NumberFormat. While the review comments mention that + '' is an unconventional pattern for string conversion, JavaScript's type coercion actually handles the division correctly—the string is automatically coerced back to a number when dividing, so the calculation produces the correct result rather than NaN. The code meets all checklist requirements and produces the expected output.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example ↩

Comment thread src/scripts/main.js
Comment on lines +8 to +9
let totalPopulation =
populationValues.reduce((sum, population) => sum + population, 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.

Using + '' to convert to string is an unconventional approach. Consider removing the string concatenation and instead convert to string only when needed for display (e.g., String(totalPopulation) or .toString()). This makes the code's intent clearer.

Comment thread src/scripts/main.js
Comment on lines +11 to +12
let averagePopulation =
Math.floor(totalPopulation / populationValues.length) + '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same issue here - the division works due to JavaScript type coercion (string is converted to number), but the + '' makes the code harder to understand. Consider separating the calculation from the string conversion.

Comment thread src/styles/main.scss
margin: 0;
align-items: center;
justify-content: center;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Critical Bug: Adding + '' converts totalPopulation to a string, which breaks the division on line 12. This causes averagePopulation to become NaN. Store the numeric values first, then format them separately for display.

Comment thread src/styles/main.scss
height: 100vh;
justify-content: center;
align-items: center;
margin: 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.

Critical Bug: Since totalPopulation is a string (due to line 9), this division produces NaN. The calculation must use numeric values, not strings.

Comment thread src/styles/main.scss
font-family: Roboto, sans-serif;
counter-reset: section;

background: #eee;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Logic Issue: The code formats totalPopulation and averagePopulation after they've already been converted to strings with + ''. The formatting should be applied to the numeric values, not the string versions.

@vitalii-bondarenko-ua vitalii-bondarenko-ua 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.

Looks good

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.

3 participants