File tree Expand file tree Collapse file tree 2 files changed +15
-11
lines changed
Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ <h1>Rate Our Service</h1>
1212 < span class ="star " data ="4 " onclick ="changeRating(4) "> ★</ span >
1313 < span class ="star " data ="5 " onclick ="changeRating(5) "> ★</ 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 >
Original file line number Diff line number Diff line change 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
88submitButton . 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
1415function changeRating ( rating ) {
15- selectedRating = rating ;
16+ //function to change selected rating
17+ selectedRating = rating ; //set selected rating to the given rating
1618}
You can’t perform that action at this time.
0 commit comments