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!

loop.rb
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
PRO
KRIS NIKOLAISEN
Pro Student 49,963 Points

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.