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

mustafa attaie
mustafa attaie
8,068 Points

having difficulty modifying a method.

the current method i've placed keeps giving me syntax errors. What am i doing wrong?

def valid_command?(command)
  command = "y", "yes", "Y", "YES"
  return = true

Matt Coston
Matt Coston
18,425 Points

Try adding the OR operator ||
command = "y" || "yes" || "Y" || "YES"

edit: Also try using an if statement instead of just assigning command to 4 things. I.E.
IF command == "y" || <more code> return true

1 Answer

You're doing great! There are some exceptions, though. Firstly, remove one of the "end" keywords. That's causing the Syntax Error thing. Second, instead of doing "y, yes, Y, YES", you have to compare "command" with each of them. Also, you should use "||" for the or operators instead of ", ". Third, "return = true" is like saying "take this variable called 'result' and assign it to true", so get rid of that "=" sign. Lastly, you aren't always gonna return "true", so try returning a variable called "valid" that I have assigned. Try my code if you don't understand what I said:

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