Erik Bonn3,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.
# 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
Angela Visnesky20,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!