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!
Oldest comments (2)
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:
Perhaps whenever you click a rating button set a
data
attribute on the submit button. Then when you click submit, read thatdata
attribute. See the Mozilla Developer docs on DataThank you so much. I will look into this and hope that it works 🤞🏾