Challenge 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
Jennifer NordellTreehouse Staff
Hi 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
stringthat 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
ifstatement also needs an
I think maybe you can get it with these hints, but let me know if you're still stuck!
Ha! 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! :)