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 trial

Ruby

Ruby 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
STAFF
Jason Seifer
Treehouse Guest Teacher

You're close! It looks like you need to put quotes around the e to let Ruby know it's a string :)

missed that :)

Thank you Guys, for all your help. that was the issue I was running into.

You 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

This worked loop do answer = get_answer break if answer == 'e' end

answer = 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.

loop 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