Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
'use strict';

// write your code here
const population = document.querySelectorAll('.population');

const getTotalSum = (expectedResult) => {
let total = 0;
let result = '';

population.forEach((populationContent) => {
const numberString = populationContent.textContent.replace(/,/g, '');

total += Number(numberString);
});

result = total.toLocaleString();

if (expectedResult === 'total') {
return result;
}

result = Math.round(total / population.length);

result = result.toLocaleString();

return result;
};

const totalResult = getTotalSum('total');
const avarage = getTotalSum('');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a small typo in this variable name. It should be average.


document.querySelector('.total-population').textContent = totalResult;
document.querySelector('.average-population').textContent = avarage;
2 changes: 1 addition & 1 deletion src/styles/_fonts.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@font-face {
font-family: Roboto, Arial, Helvetica, sans-serif;
src: url('../fonts/Roboto-Regular-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
src: url('../fonts/Roboto-Regular-webfont.woff') format('woff');
Comment on lines 1 to +5
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the task requirements, only the main.js file should be modified. Please remove this file and other style files from your submission.

}
36 changes: 21 additions & 15 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
@import 'fonts';

body {
background: #eee;
display: flex;
margin: 0;
align-items: center;
justify-content: center;

width: 100vw;
height: 100vh;
justify-content: center;
align-items: center;
margin: 0;

font-family: Roboto, sans-serif;
counter-reset: section;

background: #eee;
}

h1 {
Expand All @@ -18,28 +20,32 @@ h1 {

.list {
margin: 32px 0;
list-style: none;
padding: 0;
list-style: none;
&__item {
margin: 8px;
border-bottom: 1px solid darkgrey;
position: relative;

display: flex;
justify-content: space-between;
padding: 4px 4px 4px 30px;
position: relative;

img {
margin-right: 8px;
}
margin: 8px;
padding: 4px 4px 4px 30px;
border-bottom: 1px solid darkgrey;

&::before {
color: #565754;
counter-increment: section;
content: counter(section);
counter-increment: section;

position: absolute;
top: 50%;
left: 5px;
transform: translateY(-60%);

color: #565754;
}

img {
margin-right: 8px;
}
}
}
Expand Down
Loading