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 trialSol Caceres
2,432 PointsChallenge 1 of 1 -Ruby Loops Need help
Im having trouble passing this Loops challenge. Any help would be much appreciated!
def repeat(string, times)
fail "times must be 1 or more" if times < 1
counter = 0
loop do
# YOUR CODE HERE
print fail
counter +1
if counter ==times
break
end
end
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! I feel like you're doing fairly well here, so I'm going to give some hints:
- You're supposed to print the value of
string
that was passed into the function, but you're trying to print a fail message - You add 1 to counter but never actually assign it back into counter. That calculation is sort of floating out in limbo.
- There are two ways to add 1 to counter and reassign it back into counter
- Your
if
statement also needs anend
statement
I think maybe you can get it with these hints, but let me know if you're still stuck!
Sol Caceres
2,432 PointsHa! Totally just got it. I guess for some reason I thought that fail message was the text I was supposed to print? I reassigned the 1 back into the counter and then once I added "end" to my if statement that made it work. Thanks alot Jennifer! :)