Javascript string concatenation with mod operator - Javascript Operator

Javascript examples for Operator:Arithmetic Operator

Description

Javascript string concatenation with mod 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(){/*  w w  w .  j a  v a 2 s  . c  o m*/
let width = 8, height = 8, board = "";
for(let i = 0; i < height; i++) {
    for(let j = 0; j < width; j++) {
        if((i % 2 === 0 && j % 2 === 0) || (i % 2 !== 0 && j % 2 !== 0)) {
            board += " ";
        } else {
            board += "#";
        }
    }
    board += "\n";
}
console.log(board);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials