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

I can't see why I am not passing this code challenge

It keeps saying try again

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Ben,

There are a couple things going wrong here.

  1. You are comparing a variable answer to the values, but there is no such variable. The values that would be passed in are being passed to the parameter in the function which is named command. This is the variable name that you need to be using to compare the values.
  2. The instructions say to make the method "return true when passed the following values" but you are trying to assign the value (again to a variable that doesn't exist). Here, if the condition passes, all you want the method to do is return true, not assign or reassign anything. Methods can do all of this; however, this challenge is just looking for the method to return a value ("true" in this case).

If you fix those up, the challenge will pass. :)

Keep Coding! :dizzy: