Skip to content

Instantly share code, notes, and snippets.

@nw
Created October 15, 2014 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nw/1f44abe5a3a7ed59a633 to your computer and use it in GitHub Desktop.
Save nw/1f44abe5a3a7ed59a633 to your computer and use it in GitHub Desktop.
hi low game
var num;
var guesses = 0;
function newGame(min, max) {
num = getRandomInt(min, max);
guesses = 0;
}
function guess(myGuess){
guesses++;
if(myGuess == num){
console.log("it took you " + guesses + " guesses");
} else if( myGuess > num ) {
console.log("lower");
} else {
console.log("higher");
}
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment