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 The Ruby Loop

Jonas Troyer
Jonas Troyer
10,912 Points

Why is this saying yo instead of hi?

Why is my code giving me back yo instead of hi, I don't see where it is inputting these statements into my code?

loop.rb
def repeat(string, times)
  fail "times must be 1 or more" if times < 1
  counter = 0
  loop do
    puts string
    counter += 1
    if counter > 4
      break
    end

  end
end

1 Answer

Brandon McClelland
Brandon McClelland
4,645 Points

You should be assigning the string to repeat when you call the repeat method.

repeat('hi', 3)

vs.

repeat('yo', 5)