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

the exercise asks me to write a ruby program using the loop method to print the string "hi" 5 times which I tried

I can't seem to find the correct coding to solve the problem,i am clearly missing something!

def repeat(string, times)
  fail "times must be 5 or more" if times < 5
  counter = 0
  loop do
   print "hi"
    counter = counter + 1
    if counter==5

1 Answer

You aren't using the parameters in your code here:

print "hi"

and here:

if counter==5

replace the hard coded values with string and times and you should be good.