This is a solution to the Interactive rating component challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
- View the optimal layout for the app depending on their device's screen size
- See hover states for all interactive elements on the page
- Select and submit a number rating
- See the "Thank you" card state after submitting a rating
- Semantic HTML5 markup
- CSS custom properties
- Flexbox
- Mobile-first workflow
- Vanilla JS
I learned about how to create JS active elements on hover in this challenge.
See the code snippets below:
cardRating.addEventListener("click", function (e) {
rating.forEach((r) => {
r.className = "rating";
});
if (e.target.classList == "rating") {
e.target.classList.add("active");
}
cardStateRate.innerHTML = e.target.innerHTML;
cardStateRate.style.fontSize = "0.7rem";
});
submitBtn.addEventListener("click", (e) => {
cardTwo.style.display = "block";
cardOne.style.display = "none";
});