Skip to content

Instantly share code, notes, and snippets.

@Murphydbuffalo
Created June 19, 2014 01:33
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 Murphydbuffalo/eeb925b50c8af09aaacc to your computer and use it in GitHub Desktop.
Save Murphydbuffalo/eeb925b50c8af09aaacc to your computer and use it in GitHub Desktop.
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