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 trialJasmine Frantz
8,299 PointsWhen I run the .rb file, I have to put a space before typing 'yes' to get the correct return. Is this some sort of bug?
print "Would you like to see your name backwards? (yes or no) " answer=gets.chomp.downcase
if answer == "yes" puts name.reverse else puts "Ok, maybe later." end
When I run the file on Console, I have to put a space before typing 'yes' to be able to get the correct return.
Also, why do I get a wrong return when I get rid of .chomp from the string? I thought the purpose of 'chomp' was to prevent line break of to remove white space. Why does it affect the return?
Francois van der Hoven
2,026 PointsFrancois van der Hoven
2,026 PointsHi Jasmine, you do not need to type a space before yes. Every character that you type in the console after `answer = gets.chomp.downcase is received and processed by gets. If you enter 'Yes', answer will contain 'Yes'; if you first type a space answer will contain ' Yes'. Notice the space at the end of (yes or no) ". This ensures that your response is positioned one character away from the question.