Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Cody Bouscaren
3,070 PointsChallenge 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!
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
Courses Plus Student 26,867 PointsAgain, 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
Courses Plus Student 23,989 PointsAnother answer that works is:
def valid_command?(command)
case command
when "y", "yes", "Y", "YES"
true
end
end

Estevan Montoya
Courses Plus Student 23,989 PointsSorry, I am not understanding the markdown syntax :/
William Li
Courses Plus Student 26,867 PointsHi, 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.
Cheers.