Can you troubleshoot my code? (solved)


#1

Hey, community!

Just learning to code here, and I need a little help troubleshooting this code. CodeAcademy said that I did everything I need to so I can move on, but something isn't computing correctly in the display.

Lines 1 and 2 work fine. It asks me for my age; Ie reply 24. Then it says "comparison of String with 18 failed."

It looks like I've followed all of the lessons and examples to a T, yet I'm receiving errors.

Please help!

print "what is your age?"
answer = gets.chomp

if answer > 18
    print "Welcome"
elsif answer == 18
    print "just made it"
else
    print "Go away..."
end


#2

answer is a string, 18 is a number. They are not compatible types.

Hopefully you have covered already how to convert types, but if not, then wrap 18 in quotes to make it a string.


#3

Mtf,

Thanks so much, I hadn't covered that yet, but now I know and that fixed the problem. Thank you so much!


#4

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