Hi Community,
I’m really new to this, so please forgive me if this question is an easy
one.
Currently I am trying to program a loop: The user is prompted for input
until he names the correct answer. However, I would like Ruby to
automatically start a process after a certain time (e.g. 60 seconds) has
passed. It should be something like “Oh my god youre not of the brainy
kind are you?”
I guess I need to break the loop and restart the if. can you tell how?
and is there also a way to launch this sequence without the user
pressing enter?
thank you!! Here is the code:
t1 = @@t + 60
t2 = @@t + 30
if
Time.now.to_i > t1.to_i
puts “#{@name} gives up: ‘Boooooring’. The numbers are in alphabetical
order!!”
elsif
Time.now.to_i > t2.to_i
puts “Think of the numbers names!”
answer = gets.chomp.downcase
while answer != “alphabetical”
puts “Wrong. New try: How are those numbers sorted?”
answer = gets.chomp.downcase
end
elsif
while answer != “alphabetical”
puts “Wrong. New try: How are those numbers sorted?”
answer = gets.chomp.downcase
end
end