Skip to content

Commit ec65c54

Browse files
committed
Add comments
1 parent 5305c64 commit ec65c54

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ <h1>Rate Our Service</h1>
1212
<span class="star" data="4" onclick="changeRating(4)">&#9733;</span>
1313
<span class="star" data="5" onclick="changeRating(5)">&#9733;</span>
1414
</div>
15-
<button type="submit" id="submit-button">Submit Rating</button>
15+
<!--button to sumbit rating--><button type="submit" id="submit-button">
16+
Submit Rating
17+
</button>
1618
<div id="rating-output"></div>
1719
<script src="main.js"></script>
1820
</body>

main.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
const ratingSystem = document.getElementById("rating-system");
2-
const submitButton = document.getElementById("submit-button");
3-
const ratingOutputText = document.getElementById("rating-output-text");
4-
let selectedRating = 0;
5-
let totalRating = 0;
6-
let numberOfRatings = 0;
1+
const ratingSystem = document.getElementById("rating-system"); //rating system container
2+
const submitButton = document.getElementById("submit-button"); //submit button
3+
const ratingOutputText = document.getElementById("rating-output-text"); //rating output text
4+
let selectedRating = 0; //selected rating
5+
let totalRating = 0; //total rating
6+
let numberOfRatings = 0; //number of ratings
77

88
submitButton.addEventListener("click", () => {
9-
totalRating += selectedRating;
10-
numberOfRatings++;
11-
ratingOutputText.textContent = `Selected rating: ${selectedRating}/5\nAverage rating: ${(totalRating / numberOfRatings).toFixed(2)}\nTotal ratings: ${numberOfRatings}`;
9+
//when submit button is clicked
10+
totalRating += selectedRating; //add selected rating to total rating
11+
numberOfRatings++; //increase number of ratings by 1
12+
ratingOutputText.textContent = `Selected rating: ${selectedRating}/5\nAverage rating: ${(totalRating / numberOfRatings).toFixed(2)}\nTotal ratings: ${numberOfRatings}`; //update rating output text
1213
});
1314

1415
function changeRating(rating) {
15-
selectedRating = rating;
16+
//function to change selected rating
17+
selectedRating = rating; //set selected rating to the given rating
1618
}

0 commit comments

Comments
 (0)