diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..6eebba7a5 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,16 @@ 'use strict'; -// write your code here +const populationElements = document.querySelectorAll('span.population'); + +const populations = Array.from(populationElements).map((span) => { + return Number(span.textContent.replace(/,/g, '')); +}); + +const total = populations.reduce((sum, n) => sum + n, 0); +const average = total / populations.length; + +document.querySelector('span.average-population').textContent = + Math.round(average).toLocaleString(); + +document.querySelector('span.total-population').textContent = + total.toLocaleString();