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 trialStefanos Ntiaz-Kamprera
2,588 Pointsthe 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
break
end
end
end
1 Answer
KRIS NIKOLAISEN
54,972 PointsYou 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.