feat: calculate average and total value-based to parsed numbers#2244
feat: calculate average and total value-based to parsed numbers#2244linska wants to merge 1 commit into
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved because it meets all the core functional requirements of the task. You correctly gather the text from the .population spans, strip thousands separators, convert the values to numbers (skipping invalid entries), compute both total and average, and then format and display those results in .total-population and .average-population using toLocaleString('en-US'). The logic is clear, concise, and stays confined to src/scripts/main.js as required, so there are no critical blockers for functionality.
There are a few non-blocking improvements you might consider for robustness and style:
- Add null checks before writing to
.total-populationand.average-populationso the code fails gracefully if those elements are missing. - Prefer
textContentoverinnerHTMLwhen inserting plain numbers to avoid any unintended HTML parsing. - If you expect noisier input, consider sanitizing population strings with something like
text.replace(/[^\d.-]/g, '')before converting toNumber.
Overall, this is a solid implementation that fulfills the task, and refining these small details will make your code even more resilient and idiomatic.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.