Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 3 years ago

interactive-rating-component-main

amaar09•240
@amaar09
A solution to the Interactive rating component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Updated...

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Elaine•11,360
    @elaineleung
    Posted almost 3 years ago

    Hi Amaar, great job here, and interesting choice with the box shadow hover (looks a bit like an eclipse)!

    I think using setTimeout is fine, but from a user experience perspective and also in a real-life situation, it's probably not necessary to return to the previous screen for this case. Rating components are usually meant for a one-time use because if the user is allowed to make more than one rating, that would affect the score and it doesn't give an accurate picture for data collection. The exception here I think is unless the user is not anonymous, as in, they have their name recorded so that the data collection team can easily see duplicated entries by the same person. Hope this helps!

    Marked as helpful
  • Eray•1,410
    @ErayBarslan
    Posted almost 3 years ago

    Hey there, excellent work on this one! Regarding your question, another option would be adding a return button. You can use setTimeout here but it displays only for 1,5 seconds which isn't enough for the user to read the page. It's better to use a higher value. Additional suggestions:

    • Right now user can submit without selecting a rate and it returns undefined value. To prevent this you can add an if state to your submit event listener function like:
    submit.addEventListener("click", () => {
      if (a) {
      /* your entire function */
    }
    })
    
    • On screens smaller than 400px, content overflows out of body. That is due to using fixed width value. Instead you can use max-width: 385px; to make your container responsive. By default it's width: auto which is taking the available space without overflowing. Giving fixed width overrides this. Aside these nothing much I'd add and happy coding :)
    Marked as helpful
  • David•7,960
    @DavidMorgade
    Posted almost 3 years ago

    Hello Amaar, congrats on finishing the challenge!

    To answer your question, I think that adding a setTimeout is the best way to get the desired effect that you want, I would give more time to the user to read the thanks you card tho.

    A little problem in your project is that the rating can be submitted even when there is no rate selected and it returns undefined!, you could use an if guard close to return if no rating was selected.

    Also checked in your code that you were selecting the buttons one by one, instead of that you could use a forEach or for loop on all your buttons and select all of them at the same time, other tricky way could be selecting the parent element and from that get the closest button, something like this:

    const ratingContainer = document.querySelector('.rate'); // here you select the container of ratings
    ratingContainer.addEventListener('click', function (e) {
        const clicked = e.target.closest('button'); // selecting the closest button
        if (!clicked) return; // if clicking outside the button returns
    
    

    Hope my feedback helps you! if you have any questions, don't hesitate to ask, great job!

    Marked as helpful

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit 1st-party linked stylesheets, and styles within <style> tags.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub