Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add solution #1503

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

an-marryKyslenko
Copy link

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a comment

Choose a reason for hiding this comment

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

Good job 👍
Let's make your code better

// write your code here
const populationCollection = document.querySelectorAll('.population');
const totalElement = document.querySelector('.total-population');
const avarangeElement = document.querySelector('.average-population');

Choose a reason for hiding this comment

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

Suggested change
const avarangeElement = document.querySelector('.average-population');
const averageElement = document.querySelector('.average-population');


return result + +number;
}, 0);
const avarange = Math.floor(total / populationCollection.length);

Choose a reason for hiding this comment

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

Suggested change
const avarange = Math.floor(total / populationCollection.length);
const average = Math.floor(total / populationCollection.length);

const avarange = Math.floor(total / populationCollection.length);

function addComma(str, diviteBy = 3) {
const numberToStirng = typeof str !== 'string' ? str.toString() : str;

Choose a reason for hiding this comment

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

Suggested change
const numberToStirng = typeof str !== 'string' ? str.toString() : str;
const numberToString = typeof str !== 'string' ? str.toString() : str;

}, 0);
const avarange = Math.floor(total / populationCollection.length);

function addComma(str, diviteBy = 3) {

Choose a reason for hiding this comment

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

Suggested change
function addComma(str, diviteBy = 3) {
function addComma(str, divideBy = 3) {

Copy link

@anastasiiavorobiova anastasiiavorobiova left a comment

Choose a reason for hiding this comment

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

Great work! Almost done!

Comment on lines 14 to 36
function addComma(str, divideBy = 3) {
const numberToString = typeof str !== 'string' ? str.toString() : str;
const result = [];

for (let i = 0; i < numberToString.length; ) {
let part = '';

if (numberToString.length % divideBy && i === 0) {
part = numberToString.slice(i, i + (numberToString.length % divideBy));

result.push(part);
i = i + (numberToString.length % divideBy);
continue;
}

part = numberToString.slice(i, i + divideBy);

result.push(part);
i = i + divideBy;
}

return result.join(',');
}

Choose a reason for hiding this comment

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

Suggested change
function addComma(str, divideBy = 3) {
const numberToString = typeof str !== 'string' ? str.toString() : str;
const result = [];
for (let i = 0; i < numberToString.length; ) {
let part = '';
if (numberToString.length % divideBy && i === 0) {
part = numberToString.slice(i, i + (numberToString.length % divideBy));
result.push(part);
i = i + (numberToString.length % divideBy);
continue;
}
part = numberToString.slice(i, i + divideBy);
result.push(part);
i = i + divideBy;
}
return result.join(',');
}

return result.join(',');
}

totalElement.innerText = addComma(total);

Choose a reason for hiding this comment

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

Suggested change
totalElement.innerText = addComma(total);
totalElement.innerText = total.toLocaleString('en-US');

}

totalElement.innerText = addComma(total);
averageElement.innerText = addComma(average );

Choose a reason for hiding this comment

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

The same thing you can accomplish here

Copy link

@anastasiiavorobiova anastasiiavorobiova left a comment

Choose a reason for hiding this comment

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

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants