Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TASK 1
- def fizzbuzz(start,finish)
- (start..finish).each do |i|
- if i % 5 == 0 && i % 3 == 0
- puts "FizzBuzz"
- elsif i % 5 == 0
- puts "Buzz"
- elsif i % 3 == 0
- puts "Fizz"
- else
- puts i
- end
- end
- end
- TASK 2 (with help)
- def fizzbuzz(start = 0, finish = 100)
- start.upto(finish) do |i|
- puts rules(i)
- end
- end
- def rules(number)
- result = ''
- result << "Fizz" if number % 3 == 0
- result << "Buzz" if number % 5 == 0
- result = result.empty? ? number : result
- end
- fizzbuzz
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement