From fd523d8e55b4a295f01d5badc768a994d4ceb4f4 Mon Sep 17 00:00:00 2001 From: Valerii Omelnyk Date: Mon, 16 Sep 2024 00:52:41 +0300 Subject: [PATCH] Solution --- src/scripts/main.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f878..42b479ea 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,15 @@ 'use strict'; -// write your code here +const populationElements = document.querySelectorAll('.population'); + +const sumPopulation = [...populationElements].reduce((acc, element) => { + return acc + +element.textContent.replaceAll(',', ''); +}, 0); + +const averagePopulation = sumPopulation / populationElements.length; + +document.querySelector('.total-population').textContent = + sumPopulation.toLocaleString('en-US'); + +document.querySelector('.average-population').textContent = + averagePopulation.toLocaleString('en-US');