Jump to content
  • 0
Sign in to follow this  
Followers 0

Question

Posted

It's funny because I can do regular JAVA all day, but this stuff gives me a headache. I am sure it is so simple, but can anyone at least give me a hint on how to turn this while loop into a do while loop?

<!DOCTYPE html>

<html>
   <head>
      <meta charset = "utf-8">
      <title>Class Average Program: Sentinel-controlled Repetition</title>
      <script>

         var total; 
         var gradeCounter; 
         var grade; 
         var gradeValue; 
         var average; 


         
         total = 0; 
         gradeCounter = 0; 
      
         
         grade = window.prompt( 
              "Enter Integer Grade, -1 to Quit:", "0" );

         
         gradeValue = parseInt( grade );

         while ( gradeValue != -1 )
         {
           
            total = total + gradeValue;

          
            gradeCounter = gradeCounter + 1;

          
            grade = window.prompt( 
                 "Enter Integer Grade, -1 to Quit:", "0" );

            
            gradeValue = parseInt( grade );
         } 

        
         if ( gradeCounter != 0 )
         {
            average = total / gradeCounter;  

            
            document.writeln( 
               "<h1>Class average is " + average + "</h1>" );
         } 
         else
            document.writeln( "<p>No grades were entered</p>" );

      </script>
   </head><body></body>
</html>


Our teacher hasn't really given us a good example of transforming them from one to the other. I'm sure it's just a case of swapping a few words around, but I am honestly not sure.

Share this post


Link to post
Share on other sites

4 answers to this question

  • 0

Posted

You're right

1 person likes this

Share this post


Link to post
Share on other sites
  • 0

Posted

Thank you much!

Share this post


Link to post
Share on other sites
  • 0

Posted

gah im with you ... i hate JS...I can program PHP, sql, java etc like a ninja... but front end scripts kill me

Share this post


Link to post
Share on other sites
  • 0

Posted

gah im with you ... i hate JS...I can program PHP, sql, java etc like a ninja... but front end scripts kill me

Same here php, java, C all make more sense :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.