Skip to content

Instantly share code, notes, and snippets.

@AJ-Acevedo
Last active April 25, 2018 23:53
Show Gist options
  • Save AJ-Acevedo/8658151 to your computer and use it in GitHub Desktop.
Save AJ-Acevedo/8658151 to your computer and use it in GitHub Desktop.
JavaScript - Fizz Buzz
#!/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);
}
#!/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