Design comparison
Solution retrospective
My project is working correctly; however, I am able to select multiple rating buttons, and the rating from the last pressed button is passed to the display section of the rating.
For example, if I have pressed 4 and 3. Then 3 out of 5 will be displayed.
I think one should not be able to select multiple ratings but I could not figure it out. If anyone could review my code and provide me with feedback, I would be really grateful.
Community feedback
- @RoksolanaVeresPosted 7 months ago
Hi, great job! About your problem with multiple ratings: you could slightly modify your JS so that each time a user clicks a button you first remove the "active" class from all the buttons and then apply it only to the button that was clicked. You can do something like this:
element.addEventListener("click", (e) => { Array.from(buttons).forEach((button) => button.classList.remove("active")); document.getElementById("submit").disabled = false; e.target.classList.add("active"); let text = e.target.innerText; document.getElementById("rate").innerHTML = `You selected ${text} out of 5`; }); }
Marked as helpful1@Talika-BajajPosted 7 months agoHi @RoksolanaVeres
Thank you for helping me out with this. I really needed some guidance.
Have a great day 😀
1@RoksolanaVeresPosted 7 months ago@Talika-Bajaj You're welcome! Have a nice day too :)
0
Please log in to post a comment
Log in with GitHubJoin 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