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

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