Created
October 1, 2020 05:41
-
-
Save fczbkk/4d89f84aa9646dd14847c8092f27be87 to your computer and use it in GitHub Desktop.
Simple game loop for "Guess the number" game
This file contains 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
const randomNumber = Math.ceil(Math.random() * 100) | |
let guessedNumber | |
do { | |
guessedNumber = Number(window.prompt(`I'm thinking of number between 1 and 100. Your guess:`)) | |
if (randomNumber > guessedNumber) { | |
window.alert(`I'm thinking of HIGHER number than that.`) | |
} | |
if (randomNumber < guessedNumber) { | |
window.alert(`I'm thinking of LOWER number than that.`) | |
} | |
} while (guessedNumber !== randomNumber) | |
window.alert('Yay, you guessed it. Congratulations!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment