From 579d4f640fd1a8cef358fc13d726c2f1dd209765 Mon Sep 17 00:00:00 2001 From: Rostyslav` Date: Wed, 6 May 2026 14:29:22 +0300 Subject: [PATCH 1/2] add task solution --- src/scripts/main.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..00f56fed9 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,18 @@ 'use strict'; -// write your code here +const populationElements = document.querySelectorAll('.population'); + +const texts = []; +populationElements.forEach(span => { + texts.push(span.textContent); +}) + +const numbers = texts.map(text => { + return parseInt(text.replace(/,/g, ''), 10); +}); + +const total = numbers.reduce((sum, num) => sum + num, 0); +const average = total / numbers.length; + +document.querySelector('.total-population').textContent = total.toLocaleString('en-US');; +document.querySelector('.average-population').textContent = average.toLocaleString('en-US'); \ No newline at end of file From bd62e895ee8a0015801f2bf8f0c3d14b5c545799 Mon Sep 17 00:00:00 2001 From: Rostyslav` Date: Wed, 6 May 2026 14:57:46 +0300 Subject: [PATCH 2/2] add task solution --- src/scripts/main.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 00f56fed9..dfcbeb8e3 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -3,16 +3,20 @@ const populationElements = document.querySelectorAll('.population'); const texts = []; -populationElements.forEach(span => { + +populationElements.forEach((span) => { texts.push(span.textContent); -}) +}); -const numbers = texts.map(text => { +const numbers = texts.map((text) => { return parseInt(text.replace(/,/g, ''), 10); }); const total = numbers.reduce((sum, num) => sum + num, 0); const average = total / numbers.length; -document.querySelector('.total-population').textContent = total.toLocaleString('en-US');; -document.querySelector('.average-population').textContent = average.toLocaleString('en-US'); \ No newline at end of file +document.querySelector('.total-population').textContent = + total.toLocaleString('en-US'); + +document.querySelector('.average-population').textContent = + average.toLocaleString('en-US');