JavaScript Algorithms: FizzBuzz

JavaScript Algorithms: FizzBuzz

Fizz…Buzz…FizzBuzz? This classic and fun little technical interview question will really tackle your understanding of the modulus operator!

FizzBuzz is a pretty simple interview question that comes up often. It’s one of those questions that after you see the answer once, you’ll always remember how to solve it from then on out. The only tricky part about this entire problem is the usage of the modulus operator. According to the MDN Web Docs, the modulus/remainder operator (%) returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. So if I write 12 % 5, it will return 2 because 5 goes into 12 twice with a remainder of 2. With that said, let’s get started:

Write a function that prints out a number from 1 to x. However, you must abide by these rules:

For every multiple of 3, print “fizz” instead of the number.

For every multiple of 5, print “buzz” instead of the number.

For every multiple of both 3 and 5, print “fizzbuzz” instead of the number.

For example, fizzBuzz(5) will return:


javascript coding programming algorithms

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Principles of Functional Programming in JavaScript That Will Make Your Coding Life Easier

Who else loves to write side-effects-free functions? I think we, as programmers, all do. Today, in this story, I will walk you through the basic principles of functional programming that will make your coding life easier.

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript. Bugs are born in many ways. Creating side effects is one of them. Some people say side effects are evil, some say they’re not.

Coding Interviews: Common Algorithms

I previously wrote about some common coding algorithms that you’ll run into on your job search. The article was received fairly well so I thought I’d do a couple more to help in your journey to becoming more familiar with algorithms.

Kadane’s Algorithm: Gateway to Dynamic Programming

This tricky Kadane’s Algorithm with a deceptively simple solution is a great introduction to more optimal problem-solving practices. Continue ...

Coding 101: Programming Language Building Blocks

This article will introduce the concepts and topics common to all programming languages, that beginners and experts must know!