-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
results #1530
base: master
Are you sure you want to change the base?
results #1530
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
'use strict'; | ||
|
||
// write your code here | ||
const bodyElement = document.body; | ||
|
||
const population = [...bodyElement.querySelectorAll('.population')]; | ||
const textTotal = bodyElement.querySelector('.total-population'); | ||
const textAverage = bodyElement.querySelector('.average-population'); | ||
|
||
const value = population.map((elem) => +elem.textContent.replaceAll(',', '')); | ||
|
||
const total = value.reduce((sum, elem) => sum + elem, 0); | ||
const average = Math.round(total / value.length); | ||
|
||
textTotal.textContent = total.toLocaleString('en-Us'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The locale string 'en-Us' should be 'en-US' to correctly specify the English language locale for the United States. |
||
textAverage.textContent = average.toLocaleString('en-Us'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The locale string 'en-Us' should be 'en-US' to correctly specify the English language locale for the United States. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
replaceAll
might not be supported in all environments. Consider usingreplace
with a global regular expression instead for better compatibility.