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

Craig Shukie
Craig Shukie
8,839 Points

Issue with my code (|| operator)

Can someone please tell me what's wrong with my code. The error I receive states "unexpected end of input, expecting keyword end"?

ruby.rb
def valid_command?(command)

  if valid_command? == ("y" || "yes" || "Y" || "YES")
    return "true"
  end
Craig Shukie
Craig Shukie
8,839 Points

I have also tried:

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

but recieve the same error!

2 Answers

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

Hi, Craig. There're some issues with the code you posted.

  • the if conditional should be checking the values against command, not valid_command?.
  • there's no need to enclose "y" || "yes" || "Y" || "YES" with parentheses
  • the return value in your code is String "true", whereas the challenge asks you to return Boolean true.
  • missing one additional closing end keyword.
def valid_command?(command)
  if command == "y" || "yes" || "Y" || "YES"
    return true
  end
end

Hope it makes sense, feel free to ask me further questions. Cheers.

Amy Kang
Amy Kang
17,188 Points

Hi. You didn't close the method with an "end".

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