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

Sebastian Giliberto
Sebastian Giliberto
1,809 Points

I forgot some of the method and def stuff. Can someone please help me on this challenge?

I dont really understand what I need to do in this challenge as I never really fully understood this part of the unit

ruby.rb
def valid_command?(command)

  if valid_command = yes
    valid_command = true

end
  valid_command(

2 Answers

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

Hi, Sebastian Giliberto

Modify the "valid_command?" method to return true when passed the following values: "y", "yes", "Y", or "YES".

This challenge is asking you to implement a valid_command? method, which check to see if the argument command is one of the following values "y", "yes", "Y", or "YES", if so, return true.

Here's one way to do it.

def valid_command?(command)
  if command == "y" || "yes" || "Y" || "YES"  # check if command is one of the four values we're looking for
    return true
  end
end

Alternatively, you can write the method body in a single line

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

Even better, you can just get rid of the if, since command == "y" || "yes" || "Y" || "YES" comparison itself will return the boolean value we're looking for.

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

Hope that helps