Skip to content

fdgdfgf#2220

Open
Yurii-Leniv wants to merge 2 commits intomate-academy:masterfrom
Yurii-Leniv:master
Open

fdgdfgf#2220
Yurii-Leniv wants to merge 2 commits intomate-academy:masterfrom
Yurii-Leniv:master

Conversation

@Yurii-Leniv
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes as there are a few critical issues preventing the code from meeting the task requirements. You have the right overall structure, but the implementation needs some adjustments to work correctly.

Here are the key areas to focus on:

  1. Incorrect Element Selectors: The selectors for fetching data (li span) and displaying results (.total, .average) are incorrect. Please make sure you are selecting the specific classes mentioned in the requirements: .population, .total-population, and .average-population.
  2. Number Parsing Error: The population numbers in the HTML contain commas, which causes Number() to return NaN. You'll need to remove the commas from the string before converting it to a number.
  3. Missing Output Formatting: The final total and average values must be formatted with a thousands separator. The toLocaleString() method is a great way to handle this.

Addressing these points will ensure your solution works as expected. You're on the right track!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

// write your code here
const inside = document.querySelector('.container');
const t = inside.querySelector('.list');
const list = t.querySelectorAll('li span');

Choose a reason for hiding this comment

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

This selector captures all span elements within each list item, including the ones with country names. The task requires getting data only from span elements with the population class. Using a more specific selector will prevent trying to convert non-numeric text to a number.

const p = Array.from(list);

const totalSum = p.reduce((acc, curr) => {
const value = Number(curr.textContent);

Choose a reason for hiding this comment

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

The population numbers in the HTML (e.g., 1,439,323,776) contain commas. The Number() function cannot parse strings with commas and will return NaN. You'll need to remove these characters before converting the string to a number.

Comment on lines +16 to +17
const l = inside.querySelector('.total');
const u = inside.querySelector('.average');

Choose a reason for hiding this comment

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

The selectors .total and .average do not match the class names specified in the task description, which are total-population and average-population. The code won't be able to find the correct elements to update.

Comment on lines +19 to +20
l.textContent = totalSum;
u.textContent = average;

Choose a reason for hiding this comment

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

Requirement #5 states that the calculated average and total numbers must be formatted with a thousands separator. Currently, they are being displayed as raw numbers. Consider using a method like toLocaleString() to format them correctly.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Excellent work on this solution! All the core requirements have been met. The code correctly calculates and displays the total and average population with the required formatting.

As a final polish to perfectly match the task's preview image, consider rounding the average population to the nearest whole number. The preview shows an integer, but your calculation can produce a decimal. You can achieve this by using Math.round() on your average variable before you format it with toLocaleString().

This is a minor suggestion, and your implementation is functionally correct. I'm approving your submission—great job!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

let average = totalSum / list.length;

totalSum = totalSum.toLocaleString('en-US');
average = average.toLocaleString('en-US');

Choose a reason for hiding this comment

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

The task's preview image shows the average population as a whole number (an integer). Your current calculation will result in a number with decimal places. Consider rounding the average value before you format it to a string to match the expected output.

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.

2 participants