Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

results #1530

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1. Replace `<your_account>` with your Github username in the link
- [DEMO LINK](https://<your_account>.github.io/js_get_data_DOM/)
- [DEMO LINK](https://maxmodrr.github.io/js_get_data_DOM/)
2. Follow [this instructions](https://mate-academy.github.io/layout_task-guideline/)
- There are no tests for this task so use `npm run lint` command instead of `npm test`

Expand Down
13 changes: 13 additions & 0 deletions src/scripts/main.js
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(',', ''));

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 using replace with a global regular expression instead for better compatibility.


const total = value.reduce((sum, elem) => sum + elem, 0);
const average = Math.round(total / value.length);

textTotal.textContent = total.toLocaleString('en-Us');

Choose a reason for hiding this comment

The 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');

Choose a reason for hiding this comment

The 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.

Loading