“Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.”
/spec/fizzbuzz_spec.cr
else
work, as well. It’s probably what you expected. Go ahead and try to refactor this into a one-liner.div_by_five
and div_by_fifteen
methods. They should work the same way, but this will let you get practice actually writing it out. Once you see this, you’re ready to advance:crystal build src/fizzbuzz.cr && ./fizzbuzz
you should see num
printed 100 times. Note that our tests didn’t actually run. Not only are they not run, they’re actually not even in the executable:if
returns a value, we could also do something like this:100.times
to (1..100).each
, to make num
go from 1 to 100 instead of from 0 to 99.