FizzBuzz Problem

Maulik SompuraMaulik Sompura
1 min read

A well know logical question that you may face in a tech interview is FizzBuzz Problem. The Problem statement is something like below:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”

A simple Javascript solution to this is given below:

for (var i = 0; i <= 100; i++) {
    if (i % 3 == 0 && i % 5 == 0) {
        console.log('FizzBuzz')
    } else if (i % 3 == 0) {
        console.log('Fizz')
    } else if (i % 5 == 0) {
        console.log('Buzz')
    } else {
        console.log(i)
    }
}

This question can be modified in several way, one of which is "if the number is multiple of 3 or 5 print Buzz else Fizz". Write a solution in comment for this one.

Fun fact: The FizzBuzz problem is discussed in StackOverflow's 2019 Annual survey

0
Subscribe to my newsletter

Read articles from Maulik Sompura directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Maulik Sompura
Maulik Sompura

Hello, I’m Maulik Sompura, a fullstack Javascript developer. I have a passion for building web applications using Node JS, React, Vue, and various databases and APIs. I can implement business logic, RESTful services, and responsive UIs from Figma designs. I am proficient in GraphQL and Express along with Infrastructure management. I have had the opportunity to work with a variety of technologies including Node JS, React JS, Vue JS, Typescript, Firebase, AWS (various services), Stripe, Cloudinary, PHP, Angular JS, ElectronJS, and ElasticSearch. I am passionate about learning new things and sharing my knowledge with others. I write about Javascript, web development, and other topics on my blog. You can also find me on Linkedin, Github, and Skype. Feel free to reach out to me if you have any questions or feedback. Thanks for reading!