From cdad4c9a9d6a2a4997f5827d2ba1befd91af4dcf Mon Sep 17 00:00:00 2001 From: GabrielSpelchuk Date: Tue, 17 Feb 2026 10:52:59 +0200 Subject: [PATCH 1/3] add solution --- src/scripts/main.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..9effc5d4c 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,24 @@ 'use strict'; // write your code here + +const populationOfCounties = document.querySelectorAll('span.population'); + +let totalPopulation = 0; +let averagePopulation = 0; + +for (const element of populationOfCounties) { + const population = element.textContent; + + const cleared = population.replace(/[^\d]/g, '').trim(); + + totalPopulation += +cleared; +} + +averagePopulation = totalPopulation / populationOfCounties.length; + +const totalPopulationElement = document.querySelector('span.total-population'); +const avgPopulationElement = document.querySelector('span.average-population'); + +totalPopulationElement.textContent = totalPopulation; +avgPopulationElement.textContent = Math.round(averagePopulation); From f7f07952e2ff87201df31bd088ce0c2fde91a987 Mon Sep 17 00:00:00 2001 From: GabrielSpelchuk Date: Tue, 17 Feb 2026 10:53:52 +0200 Subject: [PATCH 2/3] added readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42684231e..b4299b8e3 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://GabrielSpelchuk.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` From b3e7210b65feef849dfc7b9791365f7aa3ebf2f2 Mon Sep 17 00:00:00 2001 From: GabrielSpelchuk Date: Tue, 17 Feb 2026 11:36:22 +0200 Subject: [PATCH 3/3] added toLocaleString for total and avg population --- src/scripts/main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 9effc5d4c..381fe2cfc 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -20,5 +20,7 @@ averagePopulation = totalPopulation / populationOfCounties.length; const totalPopulationElement = document.querySelector('span.total-population'); const avgPopulationElement = document.querySelector('span.average-population'); -totalPopulationElement.textContent = totalPopulation; -avgPopulationElement.textContent = Math.round(averagePopulation); +totalPopulationElement.textContent = totalPopulation.toLocaleString('en-US'); + +avgPopulationElement.textContent = + Math.round(averagePopulation).toLocaleString('en-US');