Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
leny4528ylet i = 0;
while( i++ <= 100 ) {
let message = "";
i % 3 || ( message += "Fizz" );
i % 5 || ( message += "Buzz" );
console.log( message || i );
} -
You don't need a separate case for when Fizz and Buzz are together! (You probably do if you're using console.log. But there are other output functions that don't append a newline.)
-
for(var num = 0; num <= 100; num++) {
var out = "";
if(num % 3 == 0)
out += "Fizz";
if(num % 5 == 0)
out += "Buzz";
console.log(out || num);
}
Related Rants
Fizzbuzz
for (var num = 0; num <= 100; num++)
if (num % 3 == 0 && num % 5 == 0) {
console.log("FizzBuzz");
}
else if (num % 5 == 0) {
console.log("Buzz");
}
else if (num % 3 == 0) {
console.log("Fizz");
}
else {
console.log(num);
}
undefined
javascript js
eloquentjava