Created
March 20, 2013 14:02
-
-
Save teitei-tk/5204877 to your computer and use it in GitHub Desktop.
fizzbuzz@ js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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') ); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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