Skip to content

Instantly share code, notes, and snippets.

@a-leung
Created October 24, 2012 15:15
Show Gist options
  • Save a-leung/3946690 to your computer and use it in GitHub Desktop.
Save a-leung/3946690 to your computer and use it in GitHub Desktop.
random number guesser
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}"
@afeld
Copy link

afeld commented Nov 13, 2012

You should initialize the guessCount to 1, and use an if/elseif since they are mutually exclusive anyway. Lastly, the Ruby convention is to use lowercase with underscores for variable names. Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment