Can anyone explain what I am doing wrong?


Okay, so I am brand new to all coding in general. I am just starting my career and IT and have grown very interested in security. Because of this I am enrolled in security courses and, now going to try to learn this. Now I keep going through these early lessons and I think I'm just not thinking about this in the right way. I feel like I understand it, but only in the most literal sense. That is to say I don't really see how any of it applies to anything outside of making this box do things. Well anyway, there is my code and I think what I want it to do is self explanatory. The error is saying "undefined method 'integer' for "21":string". So I am assuming I haven't defined a variable somewhere but I have tried adding different things and I feel like I am just moving in the wrong direction. If someone could just let me know what I forgot to do, and maybe even have any advice about how to put this in context, it would be a tremendous help.

Thanks for reading. Code below

print "How old are you?"
user_age = gets.chomp 

if user_age > 21
    puts "Let's have a drink!"
elsif user_age < 21
    puts "Maybe in a couple years."


You need to include 21 in the first if statement. Currently, if you put in 21, nothing happens.


Would that be put inside the my statement? Or above where I declare my variable?


Sorry for the late response...

You need to change your first if statement so that it includes 21. Right now, if I ran it and put in 21, it wouldn't puts anything. You need to check if the user's age is greater than OR EQUAL TO 21.


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