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

Challenge Question

This question is exactly the same format as a previous question that I had an issue with. I followed the exact same format, but still don't seem to understand what I'm doing wrong!

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


end
end

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Again, the use of logical operators is correct, but you only need to return true, if you really wanna assign true to a local variable and return it in the next line, make sure you DON'T make your local variable the same name as the function name.

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

In fact, you don't even need the if here.

def valid_command?(command)
  (command == "y") || (command == "yes") || (command == "Y") || (command == "YES")
end
Estevan Montoya
PLUS
Estevan Montoya
Courses Plus Student 23,989 Points

Another answer that works is:

def valid_command?(command)
 case command
    when "y", "yes", "Y", "YES"
    true
  end
end
William Li
William Li
Courses Plus Student 26,868 Points

Hi, Estevan Montoya , for this method, you could simply write it as

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

It's simpler than using the case statement.

I've edited your post with proper Markdown syntax. For future reference, here's how to wrap the code for Markdown highlighting.

Code block on Treehouse

Cheers.