3. Control Flow in Ruby 2 3 and 4 else if and elsif


For each of those exercises. Codecademy says I did it right and click to move to next lesson however I get errors in the output. Let me first show you my code then the result so you know what my problem is.

print "Please enter a number:"
user_num = gets.chomp

if user_num > 5
puts "I am printed because I am greater than 5."

Please enter a number: 7
comparison of String with 5 failed

I would like to know what I've done wrong in my code to get such an output. My code looks correct and straight forward. But I'm sure there has to be something wrong. Would someone please help me?


When you read input from the console you are reading text. Comparing text to a number doesn't make sense, you would need to convert the text to a number first so that you can compare two numbers.


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