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 trialcurtis allen
28,800 PointsRuby Loop get answer loop not working
Can somebody tell me why this isn't working?
Using a loop construct, assign the value of the get_answer() method to an answer variable. Use the break keyword to exit the loop if the answer variable is equal to the string e. Assume get_answer() is already written.
http://teamtreehouse.com/library/ruby-loops/ruby-loops/loop-conditionals-2
e = "" loop do answer = get_answer() if answer == e break end end
4 Answers
Jason Seifer
Treehouse Guest TeacherYou're close! It looks like you need to put quotes around the e
to let Ruby know it's a string :)
sitkibagdat
27,311 PointsYou don't need to declare variables in Ruby before using them. Only loop is enough:
loop do
answer = get_answer
break if answer == 'e'
end
Anterrio Howard
2,625 PointsThis worked loop do answer = get_answer break if answer == 'e' end
David Quiroz
2,418 Pointsanswer = gets.chomp.downcase
does not work for some reason in treehouse. i think they dont have one of those methods. Anterrios method of get_answer works though.
Dimitri McDaniel
8,718 Pointsloop do answer = get.answer if answer == "e" break end end
remember the two ends are there .. one for the loop and the second for the if
sitkibagdat
27,311 Pointssitkibagdat
27,311 Pointsmissed that :)
curtis allen
28,800 Pointscurtis allen
28,800 PointsThank you Guys, for all your help. that was the issue I was running into.