Skip to content

Instantly share code, notes, and snippets.

@hprobotic
Last active October 9, 2018 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hprobotic/0bf3340d06b47f029b2c2e2ef4a557e5 to your computer and use it in GitHub Desktop.
Save hprobotic/0bf3340d06b47f029b2c2e2ef4a557e5 to your computer and use it in GitHub Desktop.
var x = Math.floor(Math.random() * 9) + 1;
var turns = 0;
var hint = 'Guess my number, 1-10!';
while (turns < 10) {
var guess = prompt(hint);
if (!guess) break;
guess = Number(guess);
if (guess == x) {
alert("Congratulations, you are a mind reader!");
break;
}
if (turns == 10) {
alert("You had 10 tries. GAMEOVER!")
break;
}
if (guess < x) hint = 'Your guess is lower. Guess a higher number.';
if (guess > x) hint = 'Your guess is lower. Guess a higher number.';
turns++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment