Advertisement
-Annie-

chessBoard.js

May 25th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getBoard(n) {
  2.     "use strict";
  3.     let html = `<div class="chessboard">\n`;
  4.  
  5.     for (let row = 0; row < n; row ++) {
  6.         html += `   <div>\n`;
  7.         for (let col = 0; col < n; col++) {
  8.             let color = (row + col) % 2 == 0 ? 'black' : 'white';
  9.             html += `    <span class="${color}"></span>\n`;
  10.         }
  11.  
  12.         html += `</div>\n`;
  13.     }
  14.  
  15.     html += `</div>`;
  16.     return(html);
  17. }
  18.  
  19. getBoard(3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement