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

Responsive interactive rating component

@3l-5hadday

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


Functional component.

Only major problem in my opinion is that once you click a button the hover effect disappear.

Community feedback

@LuisJimenez19

Posted

Hello, congratulations for finishing the challenge.

It would be better if you captured all the buttons and then iterated them with an array.forEach so you would save more code and you would not be repeating yourself, and to be able to remove the styles from the ones that are not selected you could do something like this:

function selectedOption(arr, current){
  arr.forEach((item)=>{
    item.classList.remove("active") // remove styles all buttons
  })
  current.classList.add("active") // add style current button
}

document.querySelectorAll("button").forEach((button,index,arr) => {
  button.addEventListener("click", ()=>{
    selectedOption(arr, arr[index])
  })
})
    .active{
        background-color: rgb(149, 158, 172);
        color: white;
    }

I hope my contribution has been useful, let's keep trying.

Marked as helpful

1

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