Created
May 30, 2014 01:01
-
-
Save theRemix/d82c82c829ca383105b4 to your computer and use it in GitHub Desktop.
Number Guesser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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