Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add task solution #1526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add task solution #1526

wants to merge 1 commit into from

Conversation

luchali
Copy link

@luchali luchali commented Oct 13, 2024

- [DEMO LINK](https://luchali.github.io/js_get_data_DOM/)

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.

Great job on your code! It is well-structured and easy to follow. Just a few minor suggestions for you to consider in the future. Keep up the good work! 👍

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

// Проходимо через кожен елемент, перевіряємо та конвертуємо текст у число
populationSpans.forEach((span) => {
const populationText = span.textContent.replace(/,/g, '');
const populationNumber = parseFloat(populationText);

Choose a reason for hiding this comment

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

You are using parseFloat to convert a string to a number. This is generally fine, but keep in mind that parseFloat will convert a string to a floating point number, which may not be what you want if you are dealing with population numbers. Consider using parseInt instead if you want to deal with whole numbers.

});

// Обчислюємо загальну кількість
const totalPopulation = populationValues.reduce((sum, value) => sum + value, 0);

Choose a reason for hiding this comment

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

You are using the reduce method to calculate the sum of an array of numbers, which is a good use of this method. However, it's important to note that this method will return NaN if the array is empty. You might want to add a check to ensure that the array is not empty before using reduce.


// Функція для форматування чисел з тисячним розділювачем
function formatNumberWithCommas(number) {
return number.toLocaleString();

Choose a reason for hiding this comment

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

You are using the toLocaleString method to format numbers with commas. This is a good approach, but keep in mind that the output will depend on the user's locale. For example, in some locales, the comma is used as a decimal separator. If you want to ensure that the number is always formatted with commas as thousands separators, you could use a more specific locale, like 'en-US'.

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