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

@sameermandve

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


What specific areas of your project would you like help with?

On JavaScript Code I need feedback.

Community feedback

@filipjuszczak

Posted

Hi!

You could use data attributes on your buttons and access the associated values in JavaScript rather than rely on innerHTML, like this:

<button class="btn active" data-value="1">1</button>
let value = e.target.dataset.value;

You might also want to prevent user from submitting if they didn't select a rating - you could do that by adding a disabled attribute to the button with a default value of true and after the user selected a rating, set the attribute to false or in the submit event listener early return if rating was not selected (you would need an additional variable, e.g. selectedRating, to store that information), then use it in the handler:

const selectedRating;

submit.addEventListener("click", () => {
    if (!selectedRating) return;
    ...
});

Marked as helpful

0

@sameermandve

Posted

@filipjuszczak Thanks I will try to implement it!!

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