diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..6ba043278 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,21 @@ 'use strict'; -// write your code here +const population = document.querySelectorAll('.population'); + +let total = 0; + +for (const item of population) { + const number = Number(item.textContent.replace(/,/g, '')); + + total = total + number; +} + +const average = total / population.length; + +const totalNumber = document.querySelector('.total-population'); + +totalNumber.textContent = total.toLocaleString(); + +const averageNumber = document.querySelector('.average-population'); + +averageNumber.textContent = average.toLocaleString();