2
I’m starting to study programming so, here’s a good beginner question.
I took the test below to learn about case
in Ruby,
current_time = ARGV.first.to_i
case current_time
when 0..45 then puts('First Haf')
when 46..90 then puts('Second Haf')
else puts('Invalid Time')
end
Everything was going well until I tried to explore the code a little more, displaying warnings for times longer than 90
or less than -1
and then it all stopped.
Follow the code that gave problem
current_time = ARGV.first.to_i
case current_time
when 0..45 then puts('First Haf')
when 46..90 then puts('Second Haf')
when > 91 then puts('Overtime')
when < -1 then puts('Game not started')
else puts('Invalid Time')
end
The message displayed on the console is
ruby case2-range-tempo-futebol.rb 91 case2-range-tempo-futebol.rb:6: syntax error, unexpected '>' when > 91 then puts('Overtime') ^ case2-range-tempo-futebol.rb:7: syntax error, unexpected keyword_when, expecting end-of-input when < -1 then puts('Game not star
In case anyone knows how to help, I’d like to thank you!
Thank you so much for the @vnbrs explanation!
– Peterson Ramos