Created
April 12, 2020 02:35
-
-
Save cannandev/7313d14c2ab431cacd1847cb75ffee5c to your computer and use it in GitHub Desktop.
vNgNzZ
This file contains hidden or 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 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