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

Interactive rating component using JS

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

Solution retrospective


I build my solution but what I figured out is : if I click the rating numbers twice, it stops hovering. But I don't know how to fix it. I want your feedback on this problem.

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 Jimin, welcome to Frontend Mentor, and I think this is a great attempt here for your first challenge! I would say the main issue is the use of inline style in JS, which would have a tendency to overwrite the CSS in your stylesheet. What I suggest is to use classes instead, where you'd have an "active" or "selected" class written in the CSS, and in your JS, all you need to do is add/remove the class when the button is selected. You can check out the CodePen I have here, which is a mini version of this challenge, and see how a class can be used for styling instead: https://codepen.io/elaineleung/pen/RwMqMxZ

    Hope this helps you out, and keep going! 😊

    Marked as helpful
  • Laharl•1,000
    @UrbanskiDev
    Posted almost 3 years ago

    Hello Jimin !

    Congratulation for finishing your project

    To answer your question, the reason your button stop hovering is because of your javascript !

    When you click on you button, this part of your code is activated :

    if(clicked) {
            numbers.forEach((number) => {
                number.style.backgroundColor = "hsl(213, 19%, 18%)";
                number.style.color = "hsl(217, 12%, 63%)";
            })
    

    This part of your code changes some styles for your buttons, with the background-color erasing the property which is inside the hover one ! Why is it erased ? It is because of a priority system with CSS.

    I think this link may help you to understand priority of CSS:

    • Priority of CSS

    Inline CSS has a higher priority than embedded and external CSS, which is why your hover doesn't work after clicking a button.

    Now that you know where is the problem, with a better understanding, it should be easier to fix !

    I hope it helps you yo understand why it wasn't working, with some clues to follow, keep learning and happy coding !

    Marked as helpful
  • Lucas 👾•104,160
    @correlucas
    Posted almost 3 years ago

    👾Hello Jimin, congratulations for your first solution!👋 Welcome to the Frontend Mentor Coding Community!

    Your solution its almost done and I’ve some tips to help you to improve it:

    Improve your component responsiveness adding flex-wrap: wrap to make the buttons automatically fit while the component scales down.

    @media (max-width: 350px) {
    .score {
        display: flex;
        justify-content: space-between;
        margin-top: 15px;
        margin-bottom: 30px;
        flex-wrap: wrap;
    }
    }
    

    You’ve used px as the unit for sizes but the problem with pixels is that its not optimized for multiple devices and screens. So a good fit its to use rem or em that have a better performance and make your site more accessible between different screen sizes and devices. REM and EM does not just apply to font size, but to all sizes as well.

    ✌️ I hope this helps you and happy coding!

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 all CSS, SCSS and Less files in your repository.

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.

How does the JavaScript validation report work?

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

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

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