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 trialYuichi Narisawa
19,548 PointsHow can I get this code right?
I'm stack again. I'm not sure why this code won't work. Any advise would help. Thanks!
def valid_command?(command)
command = get.chomp
if (command == "y" || "yes")
command = true
elsif (command == "Y" || "YES")
command = true
end
end
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! Your could would actually work if you just removed this line:
command = get.chomp
Treehouse is sending in information that gets stored in the command variable specified in the parameters. You take that variable and immediately overwrite what they just sent in by using the get.chomp
.
However, your code could still be made a bit cleaner if it looked like this:
def valid_command?(command)
if(command == "y" || command == "Y" || command == "yes" || command == "YES")
return true
end
end
It's perfectly ok to put more than 2 conditionals in one line. Hope this helps!
Yuichi Narisawa
19,548 PointsYuichi Narisawa
19,548 PointsHi, Jennifer! Thank you for your quick response. I finally get through the challenge!! :)