Answer the question
In order to leave comments, you need to log in
How can you test FizzBuzz with Ruby's MiniTest?
There is a classic FizzBuzz
def fizz_buzz
n = 0
while n < 100
n += 1
if n % 3 == 0 && n % 5 == 0
puts 'FizzBuzz'
elsif n % 3 == 0
puts 'Fizz'
elsif n % 5 == 0
puts 'Buzz'
else
puts n
end
end
end
Answer the question
In order to leave comments, you need to log in
This is not a true Ruby Way FizzBuzz, it could look something like this:
puts ((1..100).map do |i|
str = ''
str << 'Fizz' if i % 3 == 0
str << 'Buzz' if i % 5 == 0
str.empty? ? i : str
end)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question