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 task solution #1547

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

add task solution #1547

wants to merge 3 commits into from

Conversation

artuom2283
Copy link

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.


Thank you for your submission! Your code is on the right track, but there are a few critical issues that need to be addressed before we can approve the pull request:

  1. JavaScript Insertion Method: The use of insertAdjacentText('beforebegin', ...) is incorrect for updating the content of the span elements. This method inserts text before the element rather than updating its content. Please use textContent or innerText to correctly update the content of the span.average-population and span.total-population elements.

  2. SCSS Compilation: The stylesheet link currently points to a SCSS file. Browsers cannot directly interpret SCSS files, so ensure that the SCSS is compiled into a CSS file and update the link accordingly.

  3. Duplicate Script Tag: The script tag is included twice in the HTML document (lines 14-17 and line 123). This redundancy could lead to unnecessary loading of the same script. Please remove one of the script tags to streamline the code.

Once these issues are resolved, your code will be in great shape! Keep up the good work, and don't hesitate to reach out if you need further assistance. 😊

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

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

src/index.html Outdated
Comment on lines 14 to 17
<script
src="scripts\main.js"
defer
></script>

Choose a reason for hiding this comment

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

The script tag is included twice in the document (lines 14-17 and line 123). It's redundant to include the same script twice. Consider removing one of them.

src/index.html Outdated
@@ -11,6 +11,10 @@
rel="stylesheet"
href="./styles/main.scss"

Choose a reason for hiding this comment

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

The stylesheet link is pointing to a SCSS file. Browsers cannot directly interpret SCSS files; they need to be compiled to CSS. Ensure that the SCSS is compiled to a CSS file and the link is updated accordingly.

return result;
}

total.insertAdjacentText('beforebegin', formatNumber(sum));

Choose a reason for hiding this comment

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

Using insertAdjacentText('beforebegin', ...) is not appropriate here as it inserts text before the span element, not inside it. Use textContent or innerText to update the content of the span.total-population element.


total.insertAdjacentText('beforebegin', formatNumber(sum));

avgPop.insertAdjacentText('beforebegin', formatNumber(avg.toFixed(0)));

Choose a reason for hiding this comment

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

Using insertAdjacentText('beforebegin', ...) is not appropriate here as it inserts text before the span element, not inside it. Use textContent or innerText to update the content of the span.average-population element.

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

Great job on implementing the solution in main.js! 🎉 Your code successfully meets the task requirements by retrieving population data, performing calculations, and updating the DOM elements with the correct values. Here are a few points to consider for improvement:

  1. Division by Zero: Ensure that elementsCount is not zero before performing the division to calculate the average. This will prevent any division by zero errors. Adding a check for cases where there are no elements will enhance the robustness of your code.

  2. Element Existence: Before updating the innerText of the total and avgPop elements, confirm that these elements are present in the DOM. This will prevent potential errors if the elements are missing.

  3. Error Handling: Consider implementing checks to ensure that all necessary elements are found before proceeding with calculations. This will help avoid potential errors and make your code more resilient.

Overall, your solution is well-structured and fulfills the task requirements. The decision to approve this pull request is made to help you move forward with your learning journey. Please review the comments and suggestions to improve your code further. Keep up the great work and continue learning from these experiences! 🚀

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

@@ -1,3 +1,32 @@
'use strict';

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

Choose a reason for hiding this comment

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

Consider checking if the elements are found before proceeding with calculations to avoid potential errors if the elements are not present in the DOM.

@@ -1,3 +1,32 @@
'use strict';

// write your code here
const elements = document.querySelectorAll('span.population');
const total = document.querySelector('span.total-population');

Choose a reason for hiding this comment

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

Similarly, ensure that the 'total' and 'avgPop' elements are found before updating their innerText to prevent errors if they are missing.

elementsCount++;
}

const avg = sum / elementsCount;

Choose a reason for hiding this comment

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

Ensure that 'elementsCount' is not zero before performing the division to avoid division by zero errors. Consider adding a check to handle cases where there are no elements.

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