I'm building a guessing game that involves generating a number and a user visiting my page to guess it. The number is supposed to be from 1-5, and you should have only 3 tries to guess it.
So far, I've been able to get the user to be prompted, and to successfully generate a number. However, that's really about it. My main problems are:
- Getting the program to tell the user if it's an incorrect guess
Having the amount of tries successfully displayed.
<script type="text/javascript"> var guesses = 3;//The number of guesses alert ("I'm thinking of a number between 1 and 5. You've got 3 attempts to guess it"); while ( guesses > 0 ) { var number = Math.random() * 5; //Generate a number between 1 and 5 number = Math.ceil( number ); //Round it to 5 var guess = prompt (" tries remaining. Go ahead!"); guesses = guesses - 1; if (guess = number) alert ("You guessed the number!"); else alert ("Unfortunate. Try again!"); } </script> </head> <body> <script type="text/javascript"> document.write ("The number was " + number); </script> </body> </html>
To add more to the second problem, you may have noticed that I had this line of code:
var guess = prompt (" tries remaining. Go ahead!");
However, when I do this:
var guess = prompt ( + guesses " tries remaining. Go ahead!");
The code won't run
Any help would be appreciated