Ruby Ruby Loops Ruby Loops Loop Conditionals

Erik Young
Erik Young
15,016 Points

Wrong number of arguments

def get_answer(answer) answer = "" print "Type in the letter you need" answer = gets.chomp loop do if answer == "e" puts "You are awesome!" break end end end

answer = get_answer() puts "Hi #{answer}"

I've declared my variable, I'm not sure what/where the problem is.

loop.rb
def get_answer(answer)
answer = ""
print "Type in the letter you need"
answer = gets.chomp
    loop do
      if answer == "e"
        puts "You are awesome!"
    break
  end
end
end

answer = get_answer()
puts "Hi #{answer}"

1 Answer

Hi Erik,

You don't need to write the get_answer method yourself. The challenge mentions that you can assume it already exists.

You only need to write the loop which is going to use the get_answer method.

You can call the get_answer method and assign the value to your answer variable. Then you would check if it's equal to 'e' and break if it is.

Putting that together, you should have something like:

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