Last active
October 9, 2018 04:53
-
-
Save hprobotic/0bf3340d06b47f029b2c2e2ef4a557e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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