-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
17 lines (16 loc) · 949 Bytes
/
main.js
File metadata and controls
17 lines (16 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const ratingSystem = document.getElementById("rating-system"); //rating system container
const submitButton = document.getElementById("submit-button"); //submit button
const ratingOutputText = document.getElementById("rating-output-text"); //rating output text
let selectedRating = 0; //selected rating
let totalRating = 0; //total rating
let numberOfRatings = 0; //number of ratings
function changeRating(rating) {
//function to change selected rating
selectedRating = rating; //set selected rating to the given rating
}
submitButton.addEventListener("click", () => {
//when submit button is clicked
totalRating += selectedRating; //add selected rating to total rating
numberOfRatings++; //increase number of ratings by 1
ratingOutputText.textContent = `Selected rating: ${selectedRating}/5\nAverage rating: ${(totalRating / numberOfRatings).toFixed(2)}\nTotal ratings: ${numberOfRatings}`; //update rating output text
});