Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because a few checklist-required behaviors are not yet fully met, and they can lead to incorrect results at runtime. Your main logic for selecting .population spans, converting to numbers, and writing total/average (with toLocaleString) looks good, but there are some critical edge cases missing.
Critical issues to fix:
- The parsing currently only removes commas; it doesn’t trim or strip other non-digit characters (e.g. non‑breaking spaces or stray text), so
Number(text)can still produceNaNand break the calculations [CHECKLIST ITEM #11]. At the point where you readspan.innerText(insrc/scripts/main.js), normalize the string (e.g.trim(), remove\u00A0, and drop non‑numeric characters) before conversion. - After calling
Number(...), you are not checking for invalid values; per the requirements you must validate withNumber.isNaN()orNumber.isFinite()and either skip invalid entries or handle them explicitly [CHECKLIST ITEMS #11 and #12]. For example, build an array of only valid numeric populations and ignore anything that can’t be converted. - When there are no valid numeric entries (e.g. all invalid or no
.populationspans),total / populations.lengthwill divide by zero, producingNaNand an incorrect average [CHECKLIST ITEM #3]. Add a guard so that if the filtered array is empty you either set the average to 0 or avoid doing the division.
Minor but recommended improvements:
- Before writing results, check that
.total-populationand.average-populationelements exist fromdocument.querySelectorto avoid possible runtime errors, and assign the rounded average to a variable before formatting so it’s easy to test.
Once you’ve tightened the parsing, validated numbers, and handled the empty-array case, your solution will fully satisfy the functional requirements; the structure is solid and just needs these robustness fixes.
✨ 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
| const populationSpans = document.querySelectorAll('.population'); | ||
|
|
||
| const populations = Array.from(populationSpans).map((span) => { | ||
| const text = span.innerText.replace(/,/g, ''); |
There was a problem hiding this comment.
Parsing removes commas but doesn't trim or handle other possible characters (e.g. non-breaking spaces or stray text). Consider trimming and removing non-digit characters before conversion so the value is reliably convertible. This relates to checklist item #11.
| const populations = Array.from(populationSpans).map((span) => { | ||
| const text = span.innerText.replace(/,/g, ''); | ||
|
|
||
| return Number(text); |
There was a problem hiding this comment.
| }); | ||
|
|
||
| const total = populations.reduce((sum, val) => sum + val, 0); | ||
| const average = total / populations.length; |
There was a problem hiding this comment.
If populations is empty the computation total / populations.length will produce NaN or throw a logic error. Add a guard for an empty array (e.g. set average to 0 or avoid division) to satisfy correct average calculation (checklist item #3).
| const total = populations.reduce((sum, val) => sum + val, 0); | ||
| const average = total / populations.length; | ||
|
|
||
| document.querySelector('.total-population').innerText = total.toLocaleString(); |
There was a problem hiding this comment.
| document.querySelector('.total-population').innerText = total.toLocaleString(); | ||
|
|
||
| document.querySelector('.average-population').innerText = | ||
| Math.round(average).toLocaleString(); |
There was a problem hiding this comment.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
etojeDenys
left a comment
There was a problem hiding this comment.
good job, but don't forget to provide a demo link
No description provided.