diff --git a/README.md b/README.md index 36dc318d..5624b2a3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ 1. Replace `` with your Github username in the link - - [DEMO LINK](https://.github.io/js_get_data_DOM/) + - [DEMO LINK]( https://romanmartseniuk.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` + - There are no tests for this task so use `npm run lint` command instead of `npm test` ### Task: TOP 10 LARGEST COUNTRIES BY POPULATION diff --git a/src/index.html b/src/index.html index 111e9cd2..612e0810 100644 --- a/src/index.html +++ b/src/index.html @@ -12,6 +12,7 @@ href="./styles/main.scss" /> +

TOP 10 LARGEST COUNTRIES BY POPULATION

diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f878..afbce304 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,16 @@ 'use strict'; -// write your code here +const arr = Array.from(document.querySelectorAll('span.population')).map( + (el) => { + return parseInt(el.innerText.split(',').join('')); + }, +); + +const total = arr.reduce((sum, el) => sum + el, 0); + +document.querySelector('span.total-population').innerText = + total.toLocaleString('en-US'); + +document.querySelector('span.average-population').innerText = ( + total / arr.length +).toLocaleString('en-US');