menu

arrow_back Why produces an error?

by
0 votes
Why the code gives an error?

age = gets.to_i
unless age < 18
puts 'You can use this'
elsif age < 18
puts 'You are too young'
else
puts 'Enter a letter'
end


Что тут написано не правильно?

1 comment

But if the user enters 18, the fact that the program respond? :)

2 Answers

by
0 votes
And a bug meets need to think of that?

If You write the Russian language, what the above code should do, you will see the error.

age = gets.to_i

if age > 18
puts "You can use this"
else
puts "You are too young"
end


ps: этот код можно ещё подсократить, но это не относится к вопросу.
by
1 vote
The fact is that unless there option elsif (Only if)