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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    My program doesn't work

    Hey guys,

    I'm very new learning javascript, and my code doesn't work. Can you help me?

    Code:
    <!DOCTYPE HTML>
    <html lang="en-us">
    <head>
    <meta charset="utf-8">
    <title> Thinking a number ?</title>
    <script type="text/javascript">
    
    // Your JavaScript function belongs here.
      // input 
      // processing 
      // output 
    function numberGuessGame() {
        var message =
            "I'm thinking of a number between 1 and 100.
    " +
            "Try to guess it!
    " +
            "Please enter an integer between 1 and 100.";
        var answer = 38;
        var guess;
        do {
            guess = parseInt(window.prompt(message));
            if (guess < answer) {
                message = guess +
                " is too low. Please enter another integer.";
            }
            else if (guess > answer) {
                message = guess +
                " is too high. Please enter another integer.";
            }
        } while (guess!= answer);
        message = guess + " is correct!";
       window.alert(message);
    }
      
    </script>
    </head>
    
    <body>
       <button type="button" onclick="numberGuessGame()">click</button><br>
    </body>
    </html>
    Last edited by vinyl-junkie; Jun 10th, 2018 at 08:20 AM. Reason: added code tags

  2. #2
    Senior Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    1,127
    Thanks
    205
    Thanked 140 Times in 140 Posts
    Hi

    It does work after a small formatting correction (clue see var message area)

    use your error console to see if you can figure it out ---- I think you can do it

    google chrome ctrl+shift+i
    0000


 

Tags for this Thread

Posting Permissions

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