Skip to content

Instantly share code, notes, and snippets.

@fczbkk
Created October 1, 2020 05:41
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 fczbkk/4d89f84aa9646dd14847c8092f27be87 to your computer and use it in GitHub Desktop.
Save fczbkk/4d89f84aa9646dd14847c8092f27be87 to your computer and use it in GitHub Desktop.
Simple game loop for "Guess the number" game
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