-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
add task solution #1547
Conversation
artuom2283
commented
Oct 31, 2024
- DEMO LINK
There was a problem hiding this 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:
-
JavaScript Insertion Method: The use of
insertAdjacentText('beforebegin', ...)
is incorrect for updating the content of thespan
elements. This method inserts text before the element rather than updating its content. Please usetextContent
orinnerText
to correctly update the content of thespan.average-population
andspan.total-population
elements. -
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.
-
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
<script | ||
src="scripts\main.js" | ||
defer | ||
></script> |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
src/scripts/main.js
Outdated
return result; | ||
} | ||
|
||
total.insertAdjacentText('beforebegin', formatNumber(sum)); |
There was a problem hiding this comment.
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.
src/scripts/main.js
Outdated
|
||
total.insertAdjacentText('beforebegin', formatNumber(sum)); | ||
|
||
avgPop.insertAdjacentText('beforebegin', formatNumber(avg.toFixed(0))); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
-
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. -
Element Existence: Before updating the
innerText
of thetotal
andavgPop
elements, confirm that these elements are present in the DOM. This will prevent potential errors if the elements are missing. -
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'); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.