Skip to content

Instantly share code, notes, and snippets.

@dmehrotra
Last active December 21, 2015 05:09
Show Gist options
  • Save dmehrotra/6254822 to your computer and use it in GitHub Desktop.
Save dmehrotra/6254822 to your computer and use it in GitHub Desktop.
save and run this code
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