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 trialMelissa Bennett
751 PointsI think my solution is correct for this question, how do I pass to the next section without penalty?
Here is my solution, but it says that I am incorrect...
def repeat(string, times) fail "times must be 1 or more" if times < 1 counter = 0 string = "hi" times = 5
loop do
if counter == times
break
else
puts string
counter += 1
end
end
end
def repeat(string, times)
fail "times must be 1 or more" if times < 1
counter = 0
string = "hi"
times = 5
loop do
if counter == times
break
else
puts string
counter += 1
end
end
end
2 Answers
Steven Parker
231,275 PointsYour loop code is actually good!
But you added some extra stuff above where the "# YOUR CODE HERE" line used to be that is changing what the function does.
Add only the loop code to the original boilerplate and you'll pass the challenge.
Melissa Bennett
751 Pointsthank you!!
:-) Mel B.
Steven Parker
231,275 PointsMelissa Bennett — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!