Number guessing game
Number guessing game. Pure JavaScript. Code: alert("Instructions: Guess a number 1 through 100. If you want to leave, type \'stop\'."); var condition = "Guess a number 1 through 100. Type \'stop\' to leave."; var User = "???"; var i = Math.ceil(Math.random() * 100); var num = 0; while(true){ User = prompt(condition); if(User.includes("stop")){ break; } num = Number(User); if(num > i){ condition = "Try to guess lower. Guess a number 1 through 100. Type \'stop\' to leave."; } if(num < i){ condition = "Try to guess higher. Guess a number 1 through 100. Type \'stop\' to leave."; } if(num == i){ alert("Great! You guessed right!"); break; } }
Created August 5, 2020
Last updated August 5, 2020
Published August 5, 2020