4/20-lesson passes but error in console


x = gets.chomp
puts x<5 ? "#{x} < 5" : "#{x} > 5"

comparison of String with 5 failed


You're trying to compare a string to an integer. You can't do that.

That's like saying:

"cat is less than 5"

Doesn't work.


Your code should look something like my example:

puts x < z ? "I can't drive 55!" : "I'm a careful driver"


Im curious where you trying to compare the character length of the string the user inputs? because if so the code works when the .length method is added to the boolean piece of the ternary conditional expression.

like so,

x = gets.chomp
puts x.length<5 ? "#{x} < 5" : "#{x} > 5"