write fizzbuzz using only 2 checks using tenary operator - Javascript Operator

Javascript examples for Operator:Ternary Operator

Description

write fizzbuzz using only 2 checks using tenary operator

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from   www.j av a 2 s. co m
for (var x = 0; x < 100; x++) {
    result += (["fizzbuzz", "buzz", "fizz", x]
         [(x % 3 == 0 ? 0 : 1) + (x % 5 == 0 ? 0 : 2)]);
    result += "\n";
}
document.getElementById("result").innerHTML = result;
    }

      </script> 
   </head> 
   <body> 
      <pre id="result">
</pre>  
   </body>
</html>

Related Tutorials