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

master #1512

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

master #1512

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://Stako21.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
32 changes: 30 additions & 2 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
'use strict';
// 'use strict';

// write your code here
const sorce = [...document.querySelectorAll('span.population')];
const population = [];

sorce.forEach((pop) => {
const popNumber = pop.innerText.replace(/,/gi, '');

if (!isNaN(popNumber)) {
population.push(+popNumber);
}
});

const totalResult = population.reduce((acc, val) => acc + val);

const totalResultFormated = totalResult
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');

const averagrResult =
population.reduce((acc, val) => acc + val) / population.length;

const averagrResultFormated = Math.floor(averagrResult)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');

document.querySelector('span.total-population').textContent =
totalResultFormated;

document.querySelector('span.average-population').textContent =
averagrResultFormated;
Loading