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 with CSS Nesting and JavaScript

@LeviKuhaulua

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 are you most proud of, and what would you do differently next time?

I am pretty proud of completing this challenge because it is helping me get even more comfortable with HTML, CSS, and JavaScript.

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

I had an initial problem when it came to getting the value associated with the radio button in JavaScript. What I did in my CSS was to put a display: none for the input tag and then style my label based on the design file.

In my JavaScript I did the following to retrieve the value:

const ratingOptions = document.querySelectorAll('input[name="rating"')
function getRating() {
  ratingOptions.forEach(e => {
    if (e.checked) {
       return e.value
     }
  }
}

button.addEventListener('click', () => {
  let value = getRating() 
  ... rest of code where I get the element associated for the rating and replace with the value variable
}

However, I found that I kept getting undefined after I clicked the submit button. What could be causing the undefined value?

Community feedback

P
Koda👹 3,810

@kodan96

Posted

hi there! 👋

your return statement is inside the forEach loop, so it won't get returned from the outer function. you can create a value variable let value = null;,update its value within the loop and return the value variable itself on the last line within your function and you should be fine.

Hope this was helpful 🙏 Good luck and happy coding! 💪

Marked as helpful

1

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