If this code runs the "else" statement, I want it to retry from "rescue" or from "begin", i don't mind. Runnig the code ask me for an input and, when I put it, it doesn't work.
1- What can I do to make this code work with the else statement running the "retry"?
2- Eliminating "rescue" creates a "retry Syntax Error" Why?
# Creates input method
def input
x = gets.to_i
end
#Begins the first choice
begin
puts "What will you do?
1- Get a closer look
2- Go in the opposite direction
Write your input an press enter:"
rescue
#Calls input method
choice = input
if choice == 1
puts "You get a closer look and..."
elsif choice == 2
puts "You go in the opposite direction, out of trouble"
else
puts "Incorrect input, enter a number between the one's avaliables:"
end
#Retries if the choice is error
retry if choice != 1||2
end
THANKS!
Aucun commentaire:
Enregistrer un commentaire