Number Guessing Game 1-1000

Note; this uses the pop-up alert box. Game may not be supported on certain browsers.


<html>
<body>
<script>
var x = Math.floor(Math.random() * 1000) + 1;
var turns = 10;
var hint = 'Guess a number.';

while (turns > 0) {
var guess = prompt(hint +
' You have ' + turns + ' guesses left.');
if (!guess) break;
guess = Number(guess);
if (guess == x) {
document.write('<p>You Win!</p>' +
'<p><img src="https://studio.code.org/v3/assets/cmYNpjk41t_wzYp8aRo_kg/YouWin.png">');
turns = 0;
} else {
hint = 'Nope.';
if (guess < x) hint += ' Higher…';
if (guess > x) hint += ' Lower…';
turns = turns - 1;
}
}
alert('You lose! The number was: ' + x + '.');
</script>
</body>
</html>


How to play:
Simply guess a number 1-1000. You have 10 guesses. The game will only accept numbers… if you input text instead, it is an automatic game over.


Refresh the game to re-play. This was created by another user.
- Bio_Hazard1282

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License