From e3ed036367c57206bed88128eb65d149efe05131 Mon Sep 17 00:00:00 2001 From: Viktor Shchehelskyi Date: Sun, 20 Oct 2024 23:41:33 +0300 Subject: [PATCH] add task solution --- README.md | 6 +++--- src/scripts/main.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 36dc318d..26b63183 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/) +1. Replace `rekverr` with your Github username in the link + - [DEMO LINK](https://rekverr.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/scripts/main.js b/src/scripts/main.js index c6e3f878..5e26ec90 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,28 @@ 'use strict'; // write your code here +const population = [...document.querySelectorAll('.population')]; +const totalPopulation = document.querySelector('.total-population'); +const averagePopulation = document.querySelector('.average-population'); + +let total = 0; + +const setting = population + .map((el) => { + return el.textContent; + }) + .map((el) => { + return el.replaceAll(',', ''); + }) + .map((el2) => { + return +el2; + }); + +for (const ch of setting) { + total += ch; +} + +const average = total / setting.length; + +totalPopulation.textContent = total; +averagePopulation.textContent = average;