Skip to content

Instantly share code, notes, and snippets.

@theRemix
Created May 30, 2014 01:01
Show Gist options
  • Select an option

  • Save theRemix/d82c82c829ca383105b4 to your computer and use it in GitHub Desktop.

Select an option

Save theRemix/d82c82c829ca383105b4 to your computer and use it in GitHub Desktop.
Number Guesser
var input = require('input');
exports.numberguess = function(player){
var randomNumber = Math.ceil(Math.random() * 10);
input( player, 'Think of a number between 1 and 10 (q to quit)', function( guess, guesser, repeat ) {
if ( guess == 'q'){
return;
}
if ( +guess !== randomNumber ) {
if (+guess < randomNumber ) {
guesser.sendMessage('Too low - guess again');
}
if (+guess > randomNumber ) {
guesser.sendMessage('Too high - guess again');
}
repeat();
} else {
guesser.sendMessage('You guessed correctly');
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment