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.
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
William LiCourses Plus Student 26,867 Points
Again, 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 MontoyaCourses Plus Student 23,989 Points
Another answer that works is:
def valid_command?(command) case command when "y", "yes", "Y", "YES" true end end