4/20-lesson passes but error in console


#1

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

console
7
comparison of String with 5 failed


#2

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.


#3

Your code should look something like my example:

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


#4

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"