Skip to content

completed the task#2187

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

completed the task#2187
SerhiyShimko wants to merge 2 commits intomate-academy:masterfrom
SerhiyShimko:develop

Conversation

@SerhiyShimko
Copy link

No description provided.

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

Great work on the logic for calculating and formatting the population numbers! The core calculations are spot on. However, changes are needed regarding how the results are displayed on the page. The task requires updating only the text inside the <span> elements, but your code uses replaceWith(), which removes the <span> elements themselves. This alters the HTML layout, which is against the requirements. Instead of replacing the entire element, please update its content using a property like element.innerText or element.textContent.


✨ 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

resultAverage.unshift(newAveragePopulationResul.splice(-3).join(''));
}

totalPopulation.replaceWith(resultTotal.join(','));

Choose a reason for hiding this comment

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

The task requires you to replace the text inside the span element, not the element itself. Using replaceWith() removes the <span> from the document, which alters the HTML layout and can break styles. You should modify the content of the element instead, for example, by setting its innerText property.

}

totalPopulation.replaceWith(resultTotal.join(','));
averagePopulation.replaceWith(resultAverage.join(','));

Choose a reason for hiding this comment

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

Similar to the total population element, you are replacing the entire span here. The requirement is to only update the text content. Please modify the innerText of the averagePopulation element instead of replacing the whole node.

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 task! Your solution correctly calculates and displays the total and average population, meeting all the core requirements. I am happy to approve your submission.

For future improvements, here are a few suggestions to make your code even cleaner:

  • Avoid duplicate DOM queries: The document.querySelectorAll('.population') call is made twice. You can store the result from the first call and reuse it later to improve efficiency.
  • Reduce code repetition: The logic for formatting numbers with thousands separators is repeated. Consider creating a single reusable function for this, or you could use the built-in number.toLocaleString() method for a more concise solution.
  • There's a small typo in the newAvaragePopulationResult variable name.

Great job addressing the previous feedback and getting the functionality working perfectly!


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

Footnotes

  1. Rate AI review example

const population = document.querySelectorAll('.population');
const averagePopulation = document.querySelector('.average-population');
const totalPopulation = document.querySelector('.total-population');
const newPopulation = [...document.querySelectorAll('.population')];

Choose a reason for hiding this comment

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

This line queries the DOM for the same elements as on line 3. It's more efficient to query the DOM only once and reuse the resulting NodeList. The population variable from line 3 can be used directly in the for...of loop on line 9.

totalPopulationResult += Number(onePopulation.innerText.split(',').join(''));
}

const newTotalPopulationResult = String(totalPopulationResult).split('');

Choose a reason for hiding this comment

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

This logic for adding thousands separators is effective, but it's repeated again on lines 23-28. To avoid code duplication, consider creating a reusable function for this task. You could also look into the standard toLocaleString() method, which can format numbers like this in a single line.

const averagePopulationResult = Math.round(
totalPopulationResult / population.length,
);
const newAveragePopulationResul = String(averagePopulationResult).split('');

Choose a reason for hiding this comment

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

There's a small typo in this variable name. It should probably be newAveragePopulationResult to be consistent.

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