WDI Fundamentals Unit 10
Let's revisit our "FizzBuzz" activity from Unit 4, incorporating what we've learned so far about writing functions.
Your job this time will be to write a function called
fizzbuzz that takes a parameter,
num. For every number from 1 to
num, this function should print (using
console.log()) one of the following values:
fizz, if the number is divisible by 3 (but not 5).
buzz, if the number is divisible by 5 (but not 3).
fizzbuzz, if the number is divisible by both 3 and 5.
For reference, running
fizzbuzz(15) should result in the following text being printed in the console:
1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz
Once again, there's no starter code for this exercise — just use the JS Bin below. If you don't see the JS Bin, please refresh the page. Feel free to solve this problem any way you like, but consider the guidelines mentioned in the previous unit!
Test your code for several different input values. What do you get if
num is 1? 10? 30?
If you're satisfied that your code is working as expected, go ahead and move on.
Stuck? Check out the solutions to see what you can do.