Last active
April 25, 2018 23:53
-
-
Save AJ-Acevedo/8658151 to your computer and use it in GitHub Desktop.
JavaScript - Fizz Buzz
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
#!/usr/bin/env node | |
/* | |
* JavaScript Fizz Buzz using a for loop | |
* Copyright (c) 2013 AJ Acevedo | http://ajacevedo.com | |
* This content is released under the MIT License. | |
* http://www.opensource.org/licenses/mit-license.php | |
* Version: 0.1 | |
*/ | |
for ( var count = 1; count <= 100; count++) { | |
var fizzBuzz = ''; | |
if (count % 15 == 0) { | |
fizzBuzz = 'FizzBuzz'; | |
} | |
else if (count % 3 == 0) { | |
fizzBuzz = 'Fizz'; | |
} | |
else if (count % 5 == 0) { | |
fizzBuzz = 'Buzz'; | |
} | |
console.log(fizzBuzz || count); | |
} |
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
#!/usr/bin/env node | |
/* | |
* JavaScript Fizz Buzz using a while loop | |
* Copyright (c) 2013 AJ Acevedo | http://ajacevedo.com | |
* This content is released under the MIT License. | |
* http://www.opensource.org/licenses/mit-license.php | |
* Version: 0.1 | |
*/ | |
var count = 1; | |
while ( count <= 100 ) { | |
var fizzBuzz = ''; | |
if (count % 15 == 0) { | |
fizzBuzz = 'FizzBuzz'; | |
} | |
else if (count % 3 == 0) { | |
fizzBuzz = 'Fizz'; | |
} | |
else if (count % 5 == 0) { | |
fizzBuzz = 'Buzz'; | |
} | |
else { | |
fizzBuzz = null; | |
} | |
console.log(fizzBuzz || count); | |
count++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment