Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html xmlns = "http://www.w3.org/1999/xhtml">
- <head>
- <title>Class Average Program</title>
- <script type = "text/javascript">
- <!--
- var total, // sum of grades
- gradeCounter, // number of grades entered
- gradeValue, // grade value
- average, // average of all grades
- grade; // grade typed by user
- // Initialization Phase
- total = 0; // clear total
- gradeCounter = 1; // prepare to loop
- // Processing Phase
- while ( gradeCounter <= 3 ) { // loop 10 times
- // prompt for input and read grade from user
- grade = window.prompt( "Enter integer grade:", "0" );
- // convert grade from a String to an integer
- gradeValue = parseInt( grade );
- // add gradeValue to total
- total = total + gradeValue;
- // add 1 to gradeCounter
- gradeCounter = gradeCounter + 1;
- }
- // Termination Phase
- average = total / 3; // calculate the average
- // display average of exam grades
- document.writeln(
- "<h1>Class average is " + average + "</h1>" );
- // -->
- </script>
- </head>
- <body>
- <p>Click Refresh (or Reload) to run the script again</p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement