Tutorials Books Videos Forums

Change the theme! Search!
Rambo ftw!

Customize Theme


Color

Background


Done

FizzBuzz

by kirupa   |   17 May 2018

There are a bunch of challenges that can help gauge whether you have a basic grasp of programming fundamentals. None of the challenges is as famous as FizzBuzz!

The Challenge

The FizzBuzz challenge is as follows:

  1. Print a number from 1 to 100 using console.log
  2. If a number is a multiple of 3, print Fizz instead of the number
  3. If a number is a multiple of 5, print Buzz instead of the number
  4. If a number is a multiple of both 3 and 5, print FizzBuzz instead of the number

To get started, create a new HTML document with the following content as your starting point:

<!DOCTYPE html>
<html>

<head>
  <title>FizzBuzz</title>
 
</head>

<body>
  <script>
    function fizzBuzz() {
      console.log("Delete this line! This is just a test.");
    }
    fizzBuzz();
  </script>

</body>

</html>

If you preview this document in your browser, you won't see much. If you bring up your browser's developer tools, you'll see the following message printed in the Console:

If you see that message, you are in good shape to get started. Just replace that line of code and start coding up the FizzBuzz challenge.

The Result

You'll know you are done when the final result of your code running prints the following to your Console:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz 

At this point, you should have all the necessary information to get started. Now....ready, set, go!

Hints

In case you get stuck, here are a few hints that may help you out:

  1. To learn more about loops and how to execute some code over and over and over...and over again, go here
  2. If and else statements are your friend. If you don't know them, befriend them in this article.
  3. One way to check if something is divisible is to see if the remainder of the division is 0. To learn how to do that, the Numbers in JavaScript article will help you out
  4. To learn all the cool things the Console can do, check out the Console Logging basics article

If you are still stuck, post on the forums and a bunch of friendly people will help you out.

Share Your Answer

If you think you have a working solution, don't just keep it to yourself. Share it with others and get some feedback from others just like you. Post your solution to the following thread (you can see the answers if you scroll further down below) and see how your answer stacks up with what others have posted.

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.

Your support keeps this site going! 😇

Kirupa's signature!

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design 🎨, development 🤖, and business 💰 - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright KIRUPA 2025 //--