Design comparison
SolutionDesign
Solution retrospective
What are you most proud of, and what would you do differently next time?
I used a simple for-loop to log the rating as the user clicks the buttons.
let rating;
for (const numButt of numbers) {
numButt.addEventListener("click", () => {
rating = numButt.textContent;
})
}
Next time I would probably try event delegation to add event listeners to the buttons. I learned about that only after I had completed that part of the code and didn't want to redo it.
What challenges did you encounter, and how did you overcome them?The most challenging part for me was to get the thank you state to show up, while getting the rating state to disappear. In the end, I used Element.classList.remove()
and Element.classList.add()
to remove and add the "hidden" property. I also prevented the default behavior of the submit button if the user had not provided a rating.
submitBtn.addEventListener("click", (ev) => {
if (rating === undefined) {
console.log("No rating");
ev.preventDefault;
} else {
thx.classList.remove("hidden");
ratCard.classList.add("hidden");
output.textContent += `You selected ${rating} out of 5`;
}
});
Community feedback
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