Created
October 24, 2012 15:15
-
-
Save a-leung/3946690 to your computer and use it in GitHub Desktop.
random number guesser
This file contains 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
GUESS_RANGE = 100 | |
guessNumber = rand(GUESS_RANGE) | |
puts "Guess the number! (Hint: between 0 and #{GUESS_RANGE})" | |
guessCount = 0 | |
while (userGuess = gets.to_i) != guessNumber # keep getting more numbers | |
# give out hints to the user | |
puts 'Too high' if userGuess > guessNumber | |
puts 'Too low' if userGuess < guessNumber | |
guessCount = guessCount + 1 | |
end | |
puts "you got it in #{guessCount} guesses! The number is: #{guessNumber}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should initialize the
guessCount
to1
, and use anif
/elseif
since they are mutually exclusive anyway. Lastly, the Ruby convention is to use lowercase with underscores for variable names. Nice work!