@samantha-fluxSubmitted over 2 years ago
Is there a simpler way to build the record rating function? I've made five separate functions, but I wonder if it's possible to combine these?
Is there a simpler way to build the record rating function? I've made five separate functions, but I wonder if it's possible to combine these?
Hi Samantha! You can use a querySelectorAll in order to select all your buttons and than repeat the same function for each of them:
const buttons = document.querySelectorAll('.rating'); buttons.forEach(button => { ... });
forEach() function can also be used to track the index of the selected button:
buttons.forEach((button, index) => { ... });
I hope this helps!