Whats going wrong with the #times method?


#1

Im trying to rewrite this code so it uses 3.times instead of printing it out 3 times - just for practice sake

def print_thrice(string)
print(string)
end

def print_thrice_thrice(string)
print_thrice(string)
print_thrice(string)
print_thrice(string)
end

print_thrice_thrice("Howdy")

**rewritten as - **

def print_thrice(string)
** print(string)**
end

def print_thrice_thrice(string)
** 3.times{print_thrice(string)}**
**end **

print_thrice_thrice("Howdy")

 I get this error 3 times : floating literal anymore; put 0 before dot

print(string).times.3


#2

This is a recursion (a function calling itself from within the function) which is not the idea being studied. Rather we want the function to just print the string three times.

def print_thrice(string):
    3.times { print string }
end

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.