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