Fizz and buzz
Inputs
n is a whole number from 0 to 30.
Your tasks
- Create an empty list
out. - Use a loop over the whole numbers 1 up to and including
n. Add "FizzBuzz" when the number divides by both 3 and 5, "Fizz" when it divides by 3 only, "Buzz" when it divides by 5 only, and the number itself as text otherwise. - Complete
fizzBuzzso it returnsout. Return it, do not print it.
Example
With n = 15, fizzBuzz returns ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"].
Rules
- Check the "both" case first.
Test data
TEST DATA 1: n is 15
TEST DATA 2: n is 0
Practice focus
Put an if inside the loop to keep, skip or change items. Filtering, mapping and comparing neighbours show up in nearly every array question.