Print: Prints out value on a single line
Puts: Puts adds a newline to the end of the output
Learned this lesson with the Pretty Christmas Tree exercise try replacing print with puts. The reason why I got it wrong initially was because the puts ' ' below was already spacing the lines and that I needs to just print the "*" on a single line, thus print:
def print_triangle(rows) counter = 1 while counter <= rows do counter.times {print '*'} counter += 1 puts '' end end
puts print_triangle(5)
No comments:
Post a Comment