Created
February 19, 2018 23:21
-
-
Save caglarorhan/052ad19a07a2ccbb816e094f7e0e6ed1 to your computer and use it in GitHub Desktop.
FizzBuzz with ternary operators
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 fizzBuzz(num){ | |
var message=""; | |
for(x=1; x<=num; x++){ | |
// if(x%3==0 && x%5!=0){console.log('Fizz');} | |
// if(x%5==0 && x%3!=0){console.log('Buzz');} | |
// if(x%3==0 && x%5==0){console.log('FizzBuzz');} | |
// if(x%3!=0 && x%5!=0){console.log(x);} | |
p = (x%3==0); | |
q = (x%5==0); | |
console.log(p&&q?"FizzBuzz":((p&&!q)?"Fizz":((!p && q)?"Buzz":x))); | |
} | |
} | |
fizzBuzz(20); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment