If you want to go the extra mile you should think of the user experience. A hover state and the set state for the star rating should be visually distinct. The user needs to know that the change occurred on click not on hover so for example if the 2 star was selected already and the mouse hovers on the with star, stars 1-2 are filled, and stars 3-5 are now filled with a more transparent yellow which transitions to the full yellow on click.
2026-04-05 04:44:39
0
Lennert De Ryck :
Why use JS for hovering if we have CSS??
2026-02-23 05:56:59
2
Obaro :
You could have an array of stars, a star would just be an object with 2 properties: ratings and isChecked. Render the array, pass the rating as data-* use the isChecked property to either fill or not fill the star. Set onClick for each star: reset all isCheck property to false first then loop through the array, if the rating is less than or equal to the rating of the clicked star, set isChecked to true.
2026-07-08 00:30:11
0
Santiago R. :
To be honest the last part took me by surprise, I mean, I knew it was all about having the 2 states (the real and the hover one) but the Array mapping just got me. Nice video btw
2026-02-14 00:50:10
3
rudycito23 :
You need to talk about study habits. To my chagrin, I would fail a tech interview.
2026-02-12 11:08:11
2
nawealvarez :
why reinvent the wheel?
2026-03-01 23:59:25
1
🇨🇦 PiotrCAN 🇨🇦 :
That's funny, I created a quite similar widget many years ago..these days reach, Vue, and Angular have made it much simpler.
2026-02-15 16:13:21
1
holymoly :
ask claude
2026-02-18 23:48:53
1
Mikaeel :
Watashi wa stahhh
2026-02-12 11:27:01
4
To see more videos from user @codercontent, please go to the Tikwm
homepage.