Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fizzbuzz@ js
(function(){
console.log( "start fizzbuzz...\n" );
var fizzbuzz, result = [];
for ( var i = 1; i <= 100; i++ ) {
if ( i % 3 === 0 && i % 5 === 0 ) {
fizzbuzz = "fizzbuzz";
} else if ( i % 3 === 0 ) {
fizzbuzz = "fizz";
} else if ( i % 5 === 0 ) {
fizzbuzz = "buzz";
} else {
fizzbuzz = i;
}
result.push( i + ":" + fizzbuzz );
}
console.log( result.join('\n') );
})();
(function(){
console.log( "start fizzbuzz not use persent sign...\n" );
var fizzbuzz, fizz = 3, buzz = 5, result = [];
for ( var i = 1; i <= 100; i++ ) {
if ( fizz === i && buzz === i ) {
fizzbuzz = "fizzbuzz";
fizz += 3;
buzz += 5;
} else if ( fizz === i ) {
fizzbuzz = "fizz";
fizz += 3;
} else if ( buzz === i ) {
fizzbuzz = "buzz";
buzz += 5;
} else {
fizzbuzz = i;
}
result.push( i + ":" + fizzbuzz );
}
console.log( result.join('\n') );
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.