Solution: Printing a Diamond Shape
Go over the implementation of printing the diamond shape by dry-running the complex pieces of code.
Courtney's version
Press + to interact
space = " "space_count = 47.times do |row|if row < 4space_count -= 1hash_count = row * 2 + 1print space * space_countelsespace_count += 1hash_count = (7 - 1 - row) * 2 + 1print space * space_countendputs '#' * hash_countend
Explanation
Courtney’s version uses print
instead of puts
to output the spaces. The print
and puts
statements are similar except puts
outputs a newline character (indicating that the ...
Get hands-on with 1400+ tech skills courses.