Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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
populaitionvariable. 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
src/scripts/main.js
Outdated
| 'use strict'; | ||
|
|
||
| // write your code here | ||
| const populaition = document.getElementsByClassName('population'); |
There was a problem hiding this comment.
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.
src/scripts/main.js
Outdated
|
|
||
| console.log(populaition); | ||
|
|
||
| function populationNumber() { |
There was a problem hiding this comment.
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.
src/scripts/main.js
Outdated
| return allPeople; | ||
| }; | ||
|
|
||
| console.log(populationNumber(populaition)); |
There was a problem hiding this comment.
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.
src/scripts/main.js
Outdated
|
|
||
| const totalPopulation = document.getElementsByClassName('total-population'); | ||
|
|
||
| totalPopulation[0].textContent = populationNumber(populaition).toLocaleString(); |
There was a problem hiding this comment.
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.
(https://mate-academy.github.io/layout_task-guideline/)