An exercise using variables, operators, strings, numbers, and loops.
Create a file called “fizzbuzz.js”, which logs the numbers from 1 to 100 to the console, but for multiples of three (3), log the word “Fizz” instead of the number, and for multiples of five (5) log “Buzz”, and for numbers which are multiples of both three and five, log “FizzBuzz”.
For instance, the first twenty lines of output from the program would look like this:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
...
Run node fizzbuzz.js
and review its output to ensure it is functioning
correctly.
If you want to test your code as you are going along, you can run this command:
node test
See References for links to operators and language features that will be helpful in completing this assignment.
Define a function called fizzbuzz
which accepts a
single argument, max
, and logs the appropriate output up to that number. For
instance, calling fizzbuzz(5);
would log the following:
1
2
Fizz
4
Buzz
Call fizzbuzz
for the numbers 5, 13, 89, and 233.
- To begin, fork this repository.
- Create a new Cloud9 workspace from your new repository.
- Alternatively, you may clone your new repository to your computer.
- Modify the files and commit changes to complete your solution.
- Run
node test
to verify that all tests pass. - Push/sync the changes up to GitHub.
- Create a pull request on the original repository to turn in the assignment.
You are also welcome commit, push, and create a pull request before you’ve completed your solution. You can ask questions or request feedback there in your pull request. Just mention @barberboy
in your comments to get my attention.