HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

Fizz Buzz in JS

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
buzzfizzstackoverflow

Problem

This is a simple JavaScript Fizz Buzz solution based on a Codecademy exercise. I refactored it down a few lines after seeing these implementations.

I wanted to post here and see what else I can learn from this basic exercise.

for (var i = 1; i <= 20; i++) {
        var result = "";
        if (i % 3 === 0) { result = "Fizz"; }
        if (i % 5 === 0) { result += "Buzz"; }        
        console.log(result || i);  
}

Solution

A standard FizzBuzz runs from 1 to 100.

Your solution is otherwise fine. It's standard enough that it ended up being nearly identical to code that someone else wrote. We could suggest ideas, but they wouldn't necessarily be improvements.

Context

StackExchange Code Review Q#62697, answer score: 4

Revisions (0)

No revisions yet.