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 trialLenka Zajic
3,970 PointsNo idea how to do this: Modify the valid_command? method to return true when passed the following values: "y", "yes", "Y
Modify the valid_command? method to return true when passed the following values: "y", "yes", "Y", or "YES".
2 Answers
melissaorgill
Front End Web Development Techdegree Student 11,136 PointsHi! You need to write an if statment that will return true when y,Y,yes,and YES are passed to it.
def valid_command?(command)
#passing the values
if (command.downcase == "y") || (command.downcase == "yes")
return true
end
end
You could write each of the arguements out as well i.e (command=="YES") but if you put downcase it will automatically put the users input to lowercase and you don't have to type as much out.
Happy coding!
Tobias Mahnert
89,414 PointsHello Lenka,
please see the code below. The trick is to use the && operator. Its a bit tricky because they don't explicit explain to use the command as argument to check.
def valid_command?(command)
if command == 'y' or 'yes' or 'Y' or 'YES'
return true
end
end
Lenka Zajic
3,970 PointsThank-you, but I totally don't understand it. I don't remember that being explained in the previous video :(
Tobias Mahnert
89,414 PointsI understand how you feel. It takes a while to get what the teacher want and you have to think for yourself with help from the language documentation but you'll get there at some point. Brofist <3