I dont understand what is wrong with my code


Setting Up the 'If' Branch, Part 1

undefined local variable or method `string_to_check' for #

string = print ("thrings pleathe: ")
user_input = gets.chomp string
if string_to_check.include? "s"
    print ("d")
    print ("there are no s' here")


That means that you've tried to access a variable named string_to_check but you have not defined such a variable.

Nowhere in your code have you assigned a value to that variable:

string_to_check = some value

Look at your code, you have used a different variable name, user_input, to hold the value that we are checking, which is perfectly fine. Because you have defined that, it is the one that you should be using.

Do you see the sense in that now?

One more thing for you to look at. There is no reason for you to try to assign your print statement to a variable.

string = print ("thrings pleathe: ")
print "thrings pleathe: " // isn't this nicer?


string_to_check should be user_input.

You have to have an Upper Case letter in your string so that .downcase! has something to return, otherwise it stuffs up the .include method.

Hope this helps. :wink:


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