Don't get this
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.
# Assume get_answer() is already defined loop do print "Enter an answer ("e" to exit): " answer = gets.chomp break if answer == "e" end
Jennifer NordellTreehouse Staff
Hi Marguerite! There are a few problems here, and some of them have to do with following the instructions of the challenge. It's always a good idea to not do anything the challenge doesn't specifically ask for. In this case, you've printed a line and then used
gets.chomp to get the answer. However, neither of these are required nor expected by the challenge.
Take a look:
loop do answer = get_answer() if answer == "e" break end end
Here we start our loop. As indicated by the instructions and the comment already available in the code, the value of
answer will be provided by calling the function
get_answer. Now, if answer is equal to "e", the loop will break. Then we end our if statement. Then we end our loop.
Hope this helps!
edited for additional note
Alexander Davison is correct. The if statement in combination with the break can be shortened to
break if answer == "e". I have edited my answer to reflect this.
Also, a little note to Jennifer, just FYI Ruby has a shortcut.
Ruby lets you shorten this:
if answer == "e" break end
break if answer == "e"
Try it in the IRB and they should work the same :)
Just a little note