diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..8c7325ac9 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,20 @@ 'use strict'; -// write your code here +const populationElements = document.querySelectorAll('.population'); +let total = 0; + +populationElements.forEach((el) => { + const num = Number(el.innerText.replace(/,/g, '')); + + if (!isNaN(num)) { + total += num; + } +}); + +const average = Math.round(total / populationElements.length); + +document.querySelector('.total-population').innerText = + total.toLocaleString('en-US'); + +document.querySelector('.average-population').innerText = + average.toLocaleString('en-US');