Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Guess the number
function getInput() {
prompt('Please guess a number between 1 and 100.');
}
var name = prompt('Welcome! What\'s your name?');
var secretNumber = (Math.floor(Math.random() * 100) + 1);
while(!name.length > 0) {
name = prompt("Enter something for a name :)")
}
alert('Hi, ' + name + '.')
for(var input = getInput(); input != secretNumber; input = prompt('Guess again!')){
if(input < secretNumber){
alert('Too low!');
}
else if(input > secretNumber) {
alert('Too high!');
}
}
alert('You got it!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment