Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Operators and Control Structures Logical Operators The Or (||) Operator

What is wrong with my code

I know I have to use the logical or opertaor, and I used but it still isn't working.

ruby.rb
def valid_command?(command)
  if (valid_command == "y") ||
     (valid_command == "yes") ||
     (valid_command == "Y") ||
     (valid_command == "YES")
    return true
  end
end

3 Answers

It seems you're evaluating the value of the function, not the parameter that is passed to the function. Remember, parameters passed act as local variables to the function.

Here's what passed for me, you should note the comparison of command, and not valid_command:

def valid_command?(command)
  if (command == "y") || (command == "yes") || (command == "Y") || (command == "YES")
    return true
  end
end
Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

You have to use the "command" argument instead of "valid_command" to check. Like this:

def valid_command?(command)
  if (command == "y") ||
     (command == "yes") ||
     (command == "Y") ||
     (command == "YES")
    return true
  end
end

So you are checking if the argument that you receive is "y" or "yes" or "Y" or "YES". I hope that helps a little bit.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Actually not much. Not much at all. In fact I took your code and copy/pasted it and then changed out "valid_command" for "command". valid_command is the name of the function. "command" is the name of the variable you should be checking! Somewhere in there you got the two mixed up a bit. Take a look:

def valid_command?(command)
  if (command == "y") ||
     (command == "yes") ||
     (command == "Y") ||
     (command == "YES")
    return true
  end
end

thanks