-
-
Save anonymous/bb1cce633d9f58973c9f to your computer and use it in GitHub Desktop.
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
def start_game | |
# Generate | |
remaining_guesses = 10 | |
guess = nil | |
print ("Let's play a guessing game! Enter a max number: ") | |
max_number = gets.to_i | |
number_to_guess = 1 + (max_number) | |
puts ('I am thinking of a number between 1 and ' + (max_number.to_s)) | |
# Guess | |
while remaining_guesses > 0 && guess != number_to_guess | |
print ('Guess a number: ') | |
guess = gets.to_i | |
if guess == max_number | |
print ('You win!') | |
elsif guess != max_number | |
print ('You lose!') | |
remaining_guesses = remaining_guesses - 1 | |
#print remaining_guesses test | |
else | |
print ('Error: Please enter a valid number') | |
end | |
end | |
end | |
start_game() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment