www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to reset my game

Hybrid View

  1. #1
    Join Date
    May 2012
    Posts
    6

    How to reset my game

    Hi so I have this nifty lab I am doing, and I got it working very well. However, I cannot figure out how to ask the user if they want to play again. Any help?

    HTML Code:
    <html>
    <head>
    <title> Lab 11 - #3 </title>
    </head>
    <script>
        
        var guess = -1; // Set guess to a value outside the range of valid values
        for (i=1; i <= 5; i++) {
        var num1 = parseInt(Math.random()*10); // get a number between 0 and 9 
        var num2 = parseInt(Math.random()*10); // get a number between 0 and 9 
        sum = num1 + num2;
            
        // Use a while loop
    
        while (guess != sum)
        {
        
            guess = prompt("Enter the correct answer for "+num1+" + "+num2, '')
            if (guess == sum)
            {
                alert("Correct!");
                
            }
            else if (guess < sum)
            {
                alert("Guess higher ");
            }
            else
            {
                alert("Guess lower");
            }
        }    
        }
    	if (confirm("Play again?")) {
      document.reset( );
    }
    </script>
    </body>
    </html>
    ?

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Code:
    do
    {
     
      /* Your entire existing routine here */ 
     
    }while( confirm("Play again?") );
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  3. #3
    Join Date
    Nov 2011
    Posts
    64
    window.location.reload(true);

  4. #4
    Join Date
    May 2012
    Posts
    6
    thank you guys

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles