Todorov_Stanimir

06. Chess Board Data Types and Variables - More Exercise

May 24th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function chessBoard(num) {
  2.     if (num > 0) {
  3.         console.log('<div class="chessboard">');
  4.     }
  5.     for (let i = 1; i <= num; i++) {
  6.         console.log('  <div>');
  7.         for (let y = 1; y <= num; y++) {
  8.             if (i % 2 != 0) {
  9.                 if (y % 2 != 0) {
  10.                     console.log('    <span class="black"></span>');
  11.                 } else {
  12.                     console.log('    <span class="white"></span>');
  13.                 }
  14.             } else {
  15.                 if (y % 2 != 0) {
  16.                     console.log('    <span class="white"></span>');
  17.                 } else {
  18.                     console.log('    <span class="black"></span>');
  19.                 }
  20.             }
  21.         }
  22.         console.log('  </div>');
  23.     }
  24.     if (num > 0) {
  25.         console.log('</div>');
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment