From 62e09e887867982023506df516d8d03697b7b170 Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 4 Feb 2026 19:10:19 +0200 Subject: [PATCH 1/2] add task solution --- src/scripts/main.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..10a5e16ab 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,21 @@ 'use strict'; -// write your code here +const population = document.querySelectorAll('.population'); + +let total = 0; + +for (const item of population) { + const number = Number(item.textContent); + + total = total + number; +} + +const average = total / population.length; + +const totalNumber = document.querySelector('.total-population'); + +totalNumber.textContent = total.toLocaleString(); + +const averageNumber = document.querySelector('.average-population'); + +averageNumber.textContent = average.toLocaleString(); From eee862999f45bf5961e9ba426b2a1299d5d7ef11 Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 4 Feb 2026 19:17:20 +0200 Subject: [PATCH 2/2] add task solution2 --- src/scripts/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 10a5e16ab..6ba043278 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -5,7 +5,7 @@ const population = document.querySelectorAll('.population'); let total = 0; for (const item of population) { - const number = Number(item.textContent); + const number = Number(item.textContent.replace(/,/g, '')); total = total + number; }