From 27fce2c12c098c4ea1981113b388e01fd9eeff33 Mon Sep 17 00:00:00 2001 From: Maxym Modrytskyi Date: Thu, 17 Oct 2024 02:46:46 +0300 Subject: [PATCH] results --- README.md | 2 +- src/scripts/main.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 384d92ef..4c5f5112 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ 1. Replace `` with your Github username in the link - - [DEMO LINK](https://.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` diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f878..c72a73a9 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,19 @@ '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) + .toLocaleString('en-Us'); + +const average = Math.round(total / value.length).toLocaleString('en-Us'); + +textTotal.textContent = total; +textAverage.textContent = average;