I'm a beginner with Ruby, practicing looping and if statements.
I went a little off track with my course work, and tried to run the following code:
puts("Enter your age!")
age = gets.to_i
again = "Try again!"
while age <= 100
if age == 0
puts("You are very very young. " + again)
age = gets.to_i
elsif age >= 1 && age <= 5
puts("You are quite small. Though you are breathing, you may not understand this. " + again)
age = gets.to_i
else
puts("You are a capable of reading " + again)
age = gets.to_i
end
end
puts("Your age," + age + " is a good one")
When I run it, I am prompted to enter an age. If the age I enter <= 100 everything works according to the code. If not, I get the error:
rehearsal.rb:20:in
+': no implicit conversion of Fixnum into String (TypeError) from rehearsal.rb:20:in'
Other StackOverflow answers (solving this error message) I read suggested that the error was in misusing the "to_i" method. I made sure to include it, and my error is still here.
Where is my bug?