diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..37084d8ef 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,12 @@ 'use strict'; -// write your code here +const population = [...document.querySelectorAll('.population')]; +const totalText = document.querySelector('.total-population'); +const averageText = document.querySelector('.average-population'); +const total = population + .map((el) => +el.innerText.trim().replaceAll(',', '')) + .reduce((acc, cur) => acc + cur, 0); +const average = total / population.length; + +totalText.textContent = total.toLocaleString('en-US'); +averageText.textContent = Math.round(average).toLocaleString('en-US');