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 trialErik Bonn
3,624 PointsRuby 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.
# 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
1 Answer
Angela Visnesky
20,927 PointsHi 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
3,624 PointsThanks Angela! much easier! ha
Curtis Dietz
4,069 PointsCurtis Dietz
4,069 PointsI was getting "get_answer method not used" also