Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job getting the core calculations for total and average population working! However, a couple of changes are needed before this can be approved.
The primary issue is the logic for formatting numbers with thousands separators. Your current implementation is hardcoded and doesn't work correctly for all numbers, which is a key requirement. For a much simpler and more reliable solution, I recommend looking into the built-in number.toLocaleString() method.
Additionally, the task instructions specified that only the main.js file should be changed. Please revert the modifications made to the style files.
Once these issues are addressed, your solution will be in great shape. Keep up the good work!
✨ 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
src/scripts/main.js
Outdated
| population.forEach((populationContent) => { | ||
| let num = ''; | ||
|
|
||
| for (let i = 0; populationContent.textContent.length >= i; i++) { |
There was a problem hiding this comment.
The loop condition here should be i < populationContent.textContent.length. Using >= causes the loop to run one extra time where populationContent.textContent[i] will be undefined. While it doesn't break your code in this case because of how Number(undefined) is handled, it's a common source of bugs and logically incorrect.
src/scripts/main.js
Outdated
| for (let i = arrayOfNum.length - 1; i >= 0; i--) { | ||
| if (i % 3 === 0 && i !== arrayOfNum.length - 1) { | ||
| result += ','; | ||
| result += arrayOfNum[i]; | ||
| } else { | ||
| result += arrayOfNum[i]; | ||
| } | ||
| } |
There was a problem hiding this comment.
This logic for adding thousands separators is not quite right. The condition i % 3 === 0 depends on the index from the start of the number, but it should be based on groups of three digits from the end. As a result, this will format numbers incorrectly (e.g., 12345 would become 1,2345). A much simpler and more reliable way to achieve this is with the built-in number.toLocaleString() method.
src/scripts/main.js
Outdated
| return result; | ||
| } | ||
|
|
||
| result = result.split(',').join(''); |
There was a problem hiding this comment.
It's inefficient to remove the commas from the formatted result string just to calculate the average. The original numeric sum is still available in the total variable. You should use total directly to perform this calculation, for example: const average = Math.round(total / population.length);.
src/scripts/main.js
Outdated
| result = ''; | ||
|
|
||
| for (let i = arrayOfNumAvarage.length - 1; i >= 0; i--) { | ||
| if (i === 5 || i === 2) { |
There was a problem hiding this comment.
This condition is "hardcoded" and will only work for formatting a 9-digit number. This logic is not robust and will fail if the average population has a different number of digits. Your formatting logic should be generic enough to work for any number. The toLocaleString() method mentioned earlier would be a great solution here as well.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on the JavaScript logic! Your use of toLocaleString() to format the numbers is a great solution and works perfectly.
However, this submission requires a change because it includes modifications to style files, such as src/styles/main.scss. The task instructions explicitly state that only the main.js file should be modified.
Please remove the style files from your pull request and resubmit with only the changes to main.js. After that small correction, your solution will be ready to go!
✨ 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
src/scripts/main.js
Outdated
| for (let i = 0; populationContent.textContent.length > i; i++) { | ||
| if ( | ||
| Number(populationContent.textContent[i]) || | ||
| Number(populationContent.textContent[i]) === 0 | ||
| ) { | ||
| num += populationContent.textContent[i]; | ||
| } | ||
| } |
There was a problem hiding this comment.
This loop works for extracting the digits, but a more common and concise way to handle this is by using the replace() method to remove the commas from the string before converting it to a number. For example: const numberString = populationContent.textContent.replace(/,/g, '');.
src/scripts/main.js
Outdated
| return result; | ||
| } | ||
|
|
||
| result = Math.round(Number(total) / population.length); |
There was a problem hiding this comment.
Since total is already a number, wrapping it in Number() here is redundant. You can simplify this to Math.round(total / population.length).
src/scripts/main.js
Outdated
| document.querySelector('.total-population').textContent = getTotalSum('total'); | ||
| document.querySelector('.average-population').textContent = getTotalSum(''); |
There was a problem hiding this comment.
Calling getTotalSum twice causes the total to be calculated two separate times, which is inefficient. A better approach is to calculate the total only once, then derive the average from that total, and finally update both elements in the HTML.
src/styles/main.scss
Outdated
|
|
||
| body { | ||
| background: #eee; | ||
| counter-reset: section; |
There was a problem hiding this comment.
The task instructions specify that only the main.js file should be changed. Please remove any style files from your submission to adhere to this requirement.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I'm approving this solution as an educational override to help you progress, but please pay close attention to the feedback for future tasks.
Great job on the JavaScript logic! Your calculations are correct, and you've used toLocaleString() perfectly to format the numbers.
However, a critical requirement for this task was to only modify the main.js file. Your submission included changes to style files (.scss), which should be avoided. Please make sure to only commit the required files in your future pull requests.
Also, I noticed a small typo in your variable name: avarage should be average. Correcting this improves code readability.
Keep up the great work, and remember to carefully read the task requirements!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| @font-face { | ||
| font-family: Roboto, Arial, Helvetica, sans-serif; | ||
| src: url('../fonts/Roboto-Regular-webfont.woff') format('woff'); | ||
| font-weight: normal; | ||
| font-style: normal; | ||
| src: url('../fonts/Roboto-Regular-webfont.woff') format('woff'); |
There was a problem hiding this comment.
According to the task requirements, only the main.js file should be modified. Please remove this file and other style files from your submission.
| }; | ||
|
|
||
| const totalResult = getTotalSum('total'); | ||
| const avarage = getTotalSum(''); |
There was a problem hiding this comment.
There's a small typo in this variable name. It should be average.
No description provided.