diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..ac54b7411 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,23 @@ 'use strict'; +const populations = document.querySelectorAll('.population'); +const totalPopulation = document.querySelector('.total-population'); +const averagePopulation = document.querySelector('.average-population'); -// write your code here +let values = []; +let sum = 0; +let average = 0; + +populations.forEach((element, index)=> { + values.push(element.textContent); + values[index] = Number(values[index].split(',').join('')) +}); + +console.log(values); + +sum = values.reduce((sum, el) => sum + el, 0); + +average = Math.round(sum / values.length); + +averagePopulation.textContent = average.toLocaleString('en-US') + +totalPopulation.textContent = sum.toLocaleString('en-US'); \ No newline at end of file