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 Loops Ruby Loops Loop Conditionals

Erik Bonn
Erik Bonn
3,624 Points

Ruby loops.How do I assign a value of a method to a certain variable, and use a break keyword to exit?

The question states: 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 is equal to the string e. Assume get_answer() is already written.

Assume get_answer() is already defined

I have this written so far.

def get_answer() answer = "" loop do print " What is the answer? " answer = gets.chomp break if answer = "e" end end

The question says that get_answer() is already defined, but when I don't include it, it says get_answer method not used.

loop.rb
# Assume get_answer() is already defined
def get_answer()
answer = ""
  loop do
    print " What is the answer? "
    answer = gets.chomp
    break if answer = "e"
    end 
  end
Curtis Dietz
Curtis Dietz
4,069 Points

I was getting "get_answer method not used" also

1 Answer

Angela Visnesky
Angela Visnesky
20,927 Points

Hi Erik, I think you are making the challenge more complex than it is. Usually the code challenges are very strict in their requirements. Here's the code I used to pass the challenge:

loop do
  answer = get_answer()
break if 
answer == "e"
end

I hope this helps!

Erik Bonn
Erik Bonn
3,624 Points

Thanks Angela! much easier! ha