Trying "if-syntax" does not give correct result, what did i wrong?


comparison of String with 5 failed

print "insert a number"
answer = gets.chomp

x = answer
if x > 5
  print "I am big!"
elsif x == 5
  print "I am correct!"
  print "I am small!"


You are trying to compare a string with a constant.

Either: Get an integer value as the input
Or: Put 5 between inverted commas.

example: if x > "5"

P.S. I don't know Ruby. But the answer is correct. :slight_smile:


you are currently comparing a string to an integer


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.