Design comparison
Solution retrospective
Please tell me if I can improve that code. Thanks.
Community feedback
- @KathrynDavies123Posted almost 2 years ago
Hi JJ :)
This is great! The only thing I would add is some kind of functionality that the form will only be submitted when one of the rating numbers is selected. At the moment, it can be submitted when nothing is selected and it will go to the submitted state with "undefined" as the rating number.
This will require a bit of tweaking of your Javascript so that the submission function is only available once a rating has been selected.
Hope this helps a bit!
Kathryn
Marked as helpful0@JeremyPaymalPosted almost 2 years agoHello @KathrynDavies123,
I did it like this :
function submission() { if (selection.isNaN) { } else { document.getElementById("rating_state").classList.add("hidden"); document.getElementById("chosen_rating").innerText = selection; document.getElementById("thanks").classList.remove("hidden"); } }
It works but is it a good way to do it ?
Thks !
Jérémy
0@KathrynDavies123Posted almost 2 years agoHey, @JeremyPaymal
It works so first of all nice job on that!
I would say this is fine, I did the function slightly different when I solved this. I used addEventListener on the number buttons and then put the submit function directly into the event listener of the buttons, so it just would not even be active until one of the buttons was pressed.
You can see my solution here if you want to check it out: https://github.com/KathrynDavies123/interactive-rating-component
Kathryn
0@KathrynDavies123Posted almost 2 years agoHey, @JeremyPaymal
It works so first of all nice job on that!
I would say this is fine, I did the function slightly different when I solved this. I used addEventListener on the number buttons and then put the submit function directly into the event listener of the buttons, so it just would not even be active until one of the buttons was pressed.
You can see my solution here if you want to check it out: https://github.com/KathrynDavies123/interactive-rating-component
Kathryn
Marked as helpful0
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