The FizzBuzz challenge is one of the most common programming interview tasks in the world. The challenge is to write a program that will output a list of numbers, replacing every 3rd number with Fizz, and every 5th number with Buzz.
Today, you will build and iterate on this challenge, and you will teach yourselves how to use for loops along the way.
For each task, copy your code from the previous task, and extend it during the next task.
-
Can you create a JavaScript program that will output every number from 1 to 105?
- You will fail this task if your program stops short at 104 numbers. Computers are very literal!
-
Copy the code from task1.js into task2.js. Can you now replace every 3rd number with Fizz?
- Ensure your code outputs only Fizz for these numbers!
-
Can you also replace every 5th number with Buzz, and every number that satisfies both conditions with FizzBuzz?
- Ensure this outputs FizzBuzz on one line, and not two separate lines, or in the wrong order.
-
Can you continue the pattern by also replacing every 7th number with Woof, alongside the other conditions?
- The logical order to the output in the event that a number satisfies all conditions is: Fizz, then Buzz, then Woof.
If you have completed the above tasks, try the following extra tasks for a bonus challenge!
-
Can you prompt the user to input the number of lines that will be generated, or to generate a specific line?
-
Can you assign the output numbers of a generated sequence to elements in a list or array?
-
How might you attempt to replace a sequence of odd prime numbers with a new word in a list or array?
- An example list has been provided in the buzzWords array. Add your own words for higher prime numbers!