Skip to content

add task solution#2208

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

add task solution#2208
Ivadriil wants to merge 2 commits intomate-academy:masterfrom
Ivadriil:develop

Conversation

@Ivadriil
Copy link

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

(https://mate-academy.github.io/layout_task-guideline/)

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

For future reference, here are a couple of ways you could make your code even more efficient and readable:

  • Avoid Recalculation: The total population is calculated multiple times. You could calculate it once, store the result in a variable, and then reuse that variable. This is more efficient.
  • Variable Naming: There's a small typo in the populaition variable. While the code works because it's consistent, using correct spelling improves code clarity.

These are suggestions for improvement, not blockers. Your code works perfectly as is. Keep up the excellent effort!


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

Footnotes

  1. Rate AI review example

'use strict';

// write your code here
const populaition = document.getElementsByClassName('population');

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 the variable name populaition. It should be population. While the code works because the typo is consistent, it's good practice to use correct spelling for variable names to improve readability.


console.log(populaition);

function populationNumber() {

Choose a reason for hiding this comment

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

This function works by using the populaition variable from the global scope. A better practice is to pass the data the function needs as a parameter, like function populationNumber(elements). This would make the function more reusable and independent of global variables.

return allPeople;
};

console.log(populationNumber(populaition));

Choose a reason for hiding this comment

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

This console.log appears to be for debugging purposes. It's a good practice to remove such statements from the final version of your code.


const totalPopulation = document.getElementsByClassName('total-population');

totalPopulation[0].textContent = populationNumber(populaition).toLocaleString();

Choose a reason for hiding this comment

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

The populationNumber() function is called here and again on line 23. This means the code iterates through all the elements and recalculates the total sum multiple times. A more efficient approach would be to call the function once, store its result in a variable, and then use that variable for both the total and the average calculation.

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