interactive-rating-component

Solution retrospective
- i tried to introduce if-else statement so the page would not load if the rating is not selected:
submitButton.addEventListener("click", () => {
if (evaluation) {
receiptContainer.classList.remove("hidden");
mainContainer.style.display = "none";
} else {
receiptContainer.classList.add("hidden");
} });
but it didint work and i couldnt come up with another way to do it. i looked up other peoples solutions for inspiration, but they all looked so complicated and unreasonably long.
- apparently, i suck at responsiveness. this is a second project that i fail to adjust it to a mobile device.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @ozzy1136
Great job with this one!
Strictly related to the question you asked, I think it would be easier to use radio buttons instead of regular buttons. This way, you can check if a value was submitted for the rating. This solution uses the FormData API, which has great browser support.
A simple example:
// index.html ... <form> <label>1 <input type="radio" name="rating" value="one" /> </label> // More radio buttons with labels ... <input type="submit" value="Submit" /> </form> ... // app.js const formEl = document.querySelector("form"); formEl.addEventListener("submit", (e) => { e.preventDefault(); new FormData(e.target); } formEl.addEventListener("formdata", (e) => { // e.formData is a JavaScript iterator object, so you have to loop over it // data will be in the form of [name, value] // You could also do for (const [name, value] of e.formData) {...} for (const data of e.formData) { if (data[0] === "rating") { // There was a rating button selected ... } } // There was not a rating button selected ... }
Check the MDN Web Docs for more information about FormData. Using radio buttons with labels also takes more effort to make the buttons look how you need to, so I would suggest you look for guides that go over this.
I imagine you could loop over the radio buttons on submit and test for a
checked
value instead.Marked as helpful - @LucasBerta
Hi Greta, the live page is not working so I can't check what's the issue with the responsivity, but I've seen you didn't use @media queries on your project.
Try to search for "@media css" on google, you'll quickly understand it and will be able to implement it on your project for making it responsive.
Also, try to replace all px units to rem units for a better responsivity patterns. https://www.aleksandrhovhannisyan.com/blog/62-5-percent-font-size-trick/#what-about-625percent
I hope you find this feedback useful =)
Marked as helpful
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