Design comparison
Solution retrospective
Hi, this is my solution for this challenge.
I struggled with writing js code for rate buttons, I'm still a newbie when it comes to js.
If you have any ideas on what I can improve in the code or notice any errors, please let me know.
Feedback is welcome
Community feedback
- @johnnygerardPosted 10 months ago
Hello Nrosta,
I opened a pull request to improve your JavaScript code.
Inline scripts should be favored over external scripts when the amount of code is small. This saves an HTTP request.
I also changed a little bit your HTML and renamed
rate
torating
.Tell me if you find my PR useful.
Good day!
Marked as helpful1@NrotsaPosted 10 months ago@johnnygerard Thank you very much. Your PR is very useful and it is good to know that it is ok to use an inline script when code is small.
0@johnnygerardPosted 10 months ago@Astornek Thanks for your reply. I'm glad that you found it useful.
I'd like to clarify that the renaming from
rate
torating
is somewhat subjective. In general, verbs likerate
are best for functions or methods.rateButton
is a good name because it refers to an action likesortButton
. Class names are selectors and do not refer to an action, which is why I preferrating
.The choice between inline vs external script is also not clear-cut. In your case, you put your script at the end of the body. The HTML parser downloads it only at the end. An alternative is to put the external script in the
head
with adefer
attribute so that it is downloaded as soon as possible but executed after HTML parsing. You would not have to useDOMContentLoaded
event.You can learn more about this in the HTML standard.
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord