Skip to content

Instantly share code, notes, and snippets.

@cannandev
Created April 12, 2020 02:35
Show Gist options
  • Save cannandev/7313d14c2ab431cacd1847cb75ffee5c to your computer and use it in GitHub Desktop.
Save cannandev/7313d14c2ab431cacd1847cb75ffee5c to your computer and use it in GitHub Desktop.
vNgNzZ
function fizzbuzzer(max) {
function check(n) {
var msg = '';
if ( n % 3 == 0 ) { msg += "Fizz" };
if ( n % 5 == 0 ) { msg += "Buzz" };
//console.log('inside: '+ msg);
return msg || n;
}
//console.log('outside for loop: '+ msg); /* Behavior of vars in closures - they are inaccessible after the function runs.*/
for (var i = 1; i <= max; i++) {
console.log(check(i));
}
}
fizzbuzzer(15);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment