Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Interactive rating component

Nrosta 530

@Nrotsa

Desktop design screenshot for the Interactive rating component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

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

@johnnygerard

Posted

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 to rating.

Tell me if you find my PR useful.

Good day!

Marked as helpful

1

Nrosta 530

@Nrotsa

Posted

@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

@johnnygerard

Posted

@Astornek Thanks for your reply. I'm glad that you found it useful.

I'd like to clarify that the renaming from rate to rating is somewhat subjective. In general, verbs like rate are best for functions or methods. rateButton is a good name because it refers to an action like sortButton. Class names are selectors and do not refer to an action, which is why I prefer rating.

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 a defer attribute so that it is downloaded as soon as possible but executed after HTML parsing. You would not have to use DOMContentLoaded event.

You can learn more about this in the HTML standard.

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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