Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

interactive rating component | vanilla & mobile first

Alia Quinteroβ€’ 60

@aliaquintero

Desktop design screenshot for the Interactive rating component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


i am more concerned about the quality of the javascript on this project versus html + css but i am happy to hear feedback on all of it!

do you see any areas where i could refactor the javascript?

are there any potential issues with how the javascript is written?

are there any best practices with javascript that i am missing?

Community feedback

@VCarames

Posted

Hey there! πŸ‘‹ Here are some suggestions to help improve your code:

Regarding your questions,

In order to answer them, you first need to fix πŸ› οΈ your HTML;

  • To ensure that the "rating buttons" are fully accessible πŸ’―, they need to be built using a form ⚠️ (with a legend) and inside of it, there should be five input radios and each input should have a label attached to it to make the buttons accessible. Finally wrap all the inputs and labels inside a fieldset to prevent users from making more than one selection.

More Info: πŸ“š

MDN: <input type="radio">

MDN: Field Set Element

  • As for your JS, the eventListener should be on the form ⚠️ as a submit.
  • To get the β€˜rating’ ⚠️ you would use const rating = form. querySelector (" input [type= 'radio']: checked")
  • All the JS should do is display the β€˜thank you" content and hide the previous content by removing/adding the hidden attribute/class.

If you have any questions or need further clarification, feel free to reach out to me.

Happy Coding! πŸŽ†πŸŽŠπŸͺ…

1
Adrianoβ€’ 33,970

@AdrianoEscarabote

Posted

Hello Alia Quintero, how are you? I truly loved your project's outcome, however I have some advice that I hope you'll find useful:

I noticed that the content is going to the side, to solve this we can do the following:

body {
    margin: 0 auto;
}

To make the code look cleaner, we can use the forEach method:

ratingScore.forEach(element => {
  element.addEventListener("click", () => {
    ratingScore.forEach(element => element.classList.remove("selected"))
    element.classList.add("selected")
    selectedScore.innerHTML = `You selected ${element.innerText} out of 5`;
  })
}) 

The remainder is excellent.

I hope it's useful. πŸ‘

0

Please log in to post a comment

Log in with GitHub
Discord logo

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