Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to ask the question again?

    I'm having trouble having it to re-ask the window.promt after I give the window alert:
    Here is the code:
    <html>
    <head>
    <title> Guess My Number! </title>
    </head>


    <body>

    <script language = "JavaScript">

    // hw 7 - let the computer generate a number and the user guess the number

    var x, guess;

    x = Math.round(Math.random()*(100)+1);

    guess = parseInt(prompt( "I have a number between 1 to 100. Please guess it:"));

    while (guess<=99)
    {

    if (guess>x)
    window.alert("Your number is too high. Try another one.");
    else if (guess<x)
    window.alert("Your number is too low. Try another one.");
    else if (guess=x)
    window.alert("You got it! CONGRATULATIONS!!!!!");
    }


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

    What do I need to change for it to ask the : guess = parseInt(prompt( "I have a number between 1 to 100. Please guess it:")); again?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Is this an assignment?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes this is an assignment, i just need help on having to ask the prompt again

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    copy the statement that displays the prompt into the loop after the too high/low messages.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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