Problem with exercise 14, Control Flow in Ruby


When you run the code it asks you "What is your favorite number" and lets you write in any number of your choice, then says "My favorite number is 6. " like it should, but after that it displays the error message "comparison of String with 6 failed" instead of showing one of the 4 different options depending on what number you put in. What am I doing wrong?

print "What is your favorite number?"
print "My favorite number is 6. "
my_number = 6

if your_number==my_number
  print "We have the same favorite number!"
elsif your_number>my_number
  print "Your favorite number is bigger than mine!"
else your_number<my_number
  print "Your favorite number is smaller than mine!"


All you need to do is specify the data type and write gets.chomp and not just gets,


The rest of your code should work as intended. :slight_smile:


Thanks, it works now!


You're welcome :slight_smile:


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