From 704877dc0928ab50305c63d2870c418c1f50b225 Mon Sep 17 00:00:00 2001 From: ikseloi Date: Sat, 7 Mar 2026 12:05:55 +0200 Subject: [PATCH 1/2] add solution --- src/scripts/main.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index c6e3f8784..87766f4b2 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,27 @@ 'use strict'; -// write your code here +(() => { + const totalEl = document.querySelector('.total-population'); + const avgEl = document.querySelector('.average-population'); + const populationSpans = [...document.getElementsByClassName('population')]; + const numbers = populationSpans + .map(({ innerText }) => innerText.trim().replace(/\D/g, '')) + .filter((s) => s !== '') + .map((s) => Number(s)); + + if (!numbers.length) { + return; + } + + const total = numbers.reduce((sum, p) => sum + p, 0); + const average = Math.round(total / numbers.length); + const locale = 'en-US'; + + if (totalEl) { + totalEl.innerText = total.toLocaleString(locale); + } + + if (avgEl) { + avgEl.innerText = average.toLocaleString(locale); + } +})(); From 4c875d9abc8f988380addc8a99acdc15e8e0d8d9 Mon Sep 17 00:00:00 2001 From: ikseloi Date: Mon, 9 Mar 2026 09:34:39 +0200 Subject: [PATCH 2/2] add readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 42684231e..d4897e7c4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ 1. Replace `` with your Github username in the link - - [DEMO LINK](https://.github.io/js_get_data_DOM/) + - [DEMO LINK](https://ikseloi.github.io/js_get_data_DOM/) 2. Follow [this instructions](https://mate-academy.github.io/layout_task-guideline/) - - There are no tests for this task so use `npm run lint` command instead of `npm test` + - There are no tests for this task so use `npm run lint` command instead of `npm test` ### Task: TOP 9 LARGEST COUNTRIES BY POPULATION @@ -9,6 +9,7 @@ Hello! In this task, you need to parse data from the list, and based on it get t You no need to change styles or HTML layout in this task. Change only `main.js` file. Steps to do this challenge: + 1. Get all text data from `span` with class `population` 2. Make sure that the given string can be converted to a number and convert it to number. 3. Calculate average and total value-based to parsed numbers.