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 trialCraig Shukie
8,839 PointsIssue 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"?
def valid_command?(command)
if valid_command? == ("y" || "yes" || "Y" || "YES")
return "true"
end
2 Answers
William Li
Courses Plus Student 26,868 PointsHi, 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.
Craig Shukie
8,839 PointsPerfect Thanks!
Amy Kang
17,188 PointsHi. You didn't close the method with an "end".
def valid_command?(command)
if valid_command? == ("y" || "yes" || "Y" || "YES")
return "true"
end
end
Craig Shukie
8,839 PointsCraig Shukie
8,839 PointsI 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!