Last active
December 21, 2015 05:09
-
-
Save dmehrotra/6254822 to your computer and use it in GitHub Desktop.
save and run this code
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
print "enter a max value? " | |
max_value = gets.to_i | |
target_number = rand(1..max_value); | |
def game(max_value, target_number) | |
print "Guess a number between 1 and #{max_value}? " | |
user_input = gets.to_i | |
max = max_value; | |
target_value = target_number | |
if user_input == 0 || user_input > max | |
puts 'not valid' | |
game(max, target_value) | |
elsif user_input == target_value | |
puts 'Congratulations! ' | |
return true | |
elsif user_input > target_value | |
puts 'too high' | |
game(max, target_value) | |
elsif user_input < target_value | |
puts 'too low' | |
game(max, target_value) | |
end | |
end | |
game(max_value, target_number) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment