DEV Community

Chantae P.
Chantae P.

Posted on

Need help with project

So I have been working on the FrontendMentor Interactive rating component project and I am stuck!!!

So far I am able to change between the rating display and the thank you display. My struggle is figuring out how to select a different rating and displaying the corresponding messages. For example: if you select a rating of 3 the message should say: "You selected 3 out of 5". But so far, no. matter which rating you choose, the message only says "You selected 1 out of 5". Here I have my repository along with the live site so you can get a better understanding of what it is I am actually trying to explain.

I will really appreciate the help!

Top comments (2)

jeremyf profile image
Jeremy Friesen

On line 21 of script.js it looks like it's doing something unintended.

What's happening is you are looping through the array of buttons but on line 21 are always asking does the 0th element of buttonArray exist? (Which it always does). To visualize this, you could add a debug/breakpoint in your code.

I don't do much front-end coding, but here's how I'd approach this is:

  1. When I click on one of the numbers, I need to update an element with that value.
  2. When I click submit, I want to get the value of the element I updated.

Perhaps whenever you click a rating button set a data attribute on the submit button. Then when you click submit, read that data attribute. See the Mozilla Developer docs on Data

taepal467 profile image
Chantae P.

Thank you so much. I will look into this and hope that it works 🤞🏾