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

@andersonrifan

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


Hello guys! How do i make to activate the active class in only 1 button, removing the class from the previous buttons i clicked?

Community feedback

Azzumar 340

@Azzumarithm

Posted

Hey good job on completing this challenge.

Code Improvements

Before selecting another .rating-btn, you have to remove all the "active" class that you added to the previous .rating-btn meaning you have to loop again all the .rating-btn elements to find all the .rating-btn elements that contains the "active" class and remove the "active" class.

ratings.forEach((element) => {
  element.addEventListener("click", (e) => {
   
   //Code changes
    ratings.forEach((element) => {
       if (element.classList.contains("active"){
           element.classList.remove("active")
        }
      }

    e.target.classList.add("active");

    ratingScore = element.value;
    console.log(element);
  });
});

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