From b095817b8b29956bdb4d156b14c6895ae65970af Mon Sep 17 00:00:00 2001 From: Yevhenii Vlasenko Date: Mon, 16 Sep 2024 16:19:47 +0300 Subject: [PATCH] added 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 c6e3f878..6246015d 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,21 @@ 'use strict'; -// write your code here +const populationElements = document.querySelectorAll('.population'); + +let total = 0; + +populationElements.forEach((element) => { + const population = parseInt(element.textContent.replace(/,/g, '')); + + total += population; +}); + +const totalPopulationTag = document.querySelector('.total-population'); + +totalPopulationTag.textContent = total.toLocaleString(); + +const average = total / populationElements.length; + +const averagePopulationTag = document.querySelector('.average-population'); + +averagePopulationTag.textContent = average.toLocaleString();