Adriano• 34,090
@AdrianoEscarabote
Posted
Hi Arun Kanaujia Patel, how are you?
I really liked the result of your project, but I have some tips that I think you will enjoy:
Instead of using the for loop
you can use the forEach
method, it will do the same thing but the code will be cleaner and more readable!
old way:
for (let i = 0; i < valueRating.length;i++){
valueRating[i].addEventListener("click",(e) => {
V = valueRating[i].innerText;
ratingFinal.innerText = "You selected " + V + " out of 5";
valueRating[i].className = "active rating d-flex align-items-center justify-content-center";
})
}
with the forEach
method:
valueRating.forEach((element) => {
element.addEventListener("click", () => {
V = element.innerText;
ratingFinal.innerText = "You selected " + V + " out of 5";
element.className = "active rating d-flex align-items-center justify-content-center";
})
})
The rest is great!
I hope it helps... 👍
Marked as helpful
0