- 1

Why these codes do not work?

age = 18 user = gets.chomp case user when user >= age puts "welcome" when user <= age puts " leave" end

18th Apr 2017, 9:07 AM
Kelvine De Danielo
Kelvine De Danielo - avatar
4 Answers
+ 15
Because user input is a string and age is an integer. You're trying to compare different data types.
18th Apr 2017, 9:10 AM
Michael Foster
Michael Foster - avatar
+ 14
Try converting the user input to an integer using the gets.to_i method
18th Apr 2017, 9:21 AM
Michael Foster
Michael Foster - avatar
+ 13
This works: age = 18 user = gets.to_i if user >= age puts "welcome" else puts "leave" end
18th Apr 2017, 9:27 AM
Michael Foster
Michael Foster - avatar
0
what should it look like then?...i changed the value of varisble age to a string by putting double quotes...now when i run and enter any number, it gives no output
18th Apr 2017, 9:18 AM
Kelvine De Danielo
Kelvine De Danielo - avatar