From 1e237d9a3176cdc9c0d9b4d221af67f8769c3c69 Mon Sep 17 00:00:00 2001 From: Serhii Shimko Date: Tue, 17 Feb 2026 11:29:45 +0200 Subject: [PATCH 1/2] completed the task --- src/scripts/main.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..8f18eb384 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,31 @@ 'use strict'; -// write your code here +const population = document.querySelectorAll('.population'); +const averagePopulation = document.querySelector('.average-population'); +const totalPopulation = document.querySelector('.total-population'); +const newPopulation = [...document.querySelectorAll('.population')]; +let totalPopulationResult = 0; + +for (const onePopulation of newPopulation) { + totalPopulationResult += Number(onePopulation.innerText.split(',').join('')); +} + +const newTotalPopulationResult = String(totalPopulationResult).split(''); +const resultTotal = []; + +while (newTotalPopulationResult.length) { + resultTotal.unshift(newTotalPopulationResult.splice(-3).join('')); +} + +const averagePopulationResult = Math.round( + totalPopulationResult / population.length, +); +const newAveragePopulationResul = String(averagePopulationResult).split(''); +const resultAverage = []; + +while (newAveragePopulationResul.length) { + resultAverage.unshift(newAveragePopulationResul.splice(-3).join('')); +} + +totalPopulation.replaceWith(resultTotal.join(',')); +averagePopulation.replaceWith(resultAverage.join(',')); From b06ee8d03bf7369dde9480b183841a9ed872a9ea Mon Sep 17 00:00:00 2001 From: Serhii Shimko Date: Tue, 17 Feb 2026 16:09:33 +0200 Subject: [PATCH 2/2] edited by Luke --- src/scripts/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 8f18eb384..03e9dc617 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -27,5 +27,5 @@ while (newAveragePopulationResul.length) { resultAverage.unshift(newAveragePopulationResul.splice(-3).join('')); } -totalPopulation.replaceWith(resultTotal.join(',')); -averagePopulation.replaceWith(resultAverage.join(',')); +totalPopulation.innerText = resultTotal.join(','); +averagePopulation.innerText = resultAverage.join(',');