var selectedRating = null;
var rates = document.querySelectorAll(".rates").forEach((rate) => {
rate.addEventListener("click", () => {
selectedRating = rate.value;
});
});
console.log(selectedRating);
I want to update the value of seletectedRating, but my code is not working as expected. It only works when I log selectedRating inside my arrow function.