From 75b5119f22006abe282db48dc93b32a533d3c649 Mon Sep 17 00:00:00 2001 From: Marian Date: Wed, 17 Jun 2026 04:04:44 +0300 Subject: [PATCH] add 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..423b0215d 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 populations = [...populationElements].map((element) => { + const cleanString = element.textContent.replace(/,/g, ''); + + return Number(cleanString); +}); + +const total = populations.reduce((sum, current) => sum + current, 0); +const average = Math.round(total / populations.length); + +document.querySelector('.total-population').textContent = + total.toLocaleString('en-US'); + +document.querySelector('.average-population').textContent = + average.toLocaleString('en-US');