My HTML page features a unique rating system created with radio buttons that resemble stars when filled in. The CSS styling gives them an appealing design. Additionally, I have included a submit button to display the selected star count when clicked.
Here is my current task:
I am seeking to develop a Javascript program that calculates the average star rating based on user submissions. For example, if a user clicks 3 stars and submits, then 5 stars and submits again, I want the program to output: "the average star rating is 4". Subsequent submissions should update this average accordingly.
Any assistance would be greatly appreciated!
I have come across a code snippet that calculates the average, but I am unsure how to integrate it into my program.
function average (numbers){
var sum = 0;
for (var i = 0; i < numbers.length; i++){
sum += numbers[i];
}
return sum / numbers.length;
}
average([1, 2, 3, 4, 5])