Advertisement
Spocoman

06. Chess Board

Jan 19th, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(num) {
  2.  
  3.     console.log(`<div class="chessboard">`);
  4.     for (let i = 0; i < num; i++){
  5.         console.log(`  <div>`);
  6.         let color = "";
  7.         for(let j = 0; j < num; j++){
  8.             if (i % 2 === 0){
  9.                 j % 2 === 0 ? color = "black" : color = "white";
  10.             }else{
  11.                 j % 2 === 1 ? color = "black" : color = "white";
  12.             }
  13.             console.log(`    <span class="${color}"></span>`);
  14.         }
  15.         console.log(`  </div>`);
  16.     }
  17.     console.log(`</div>`);
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement