Guest User

Untitled

a guest
Apr 10th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <style>
  5.         body{
  6.             background: #a3cfe0;
  7.         }
  8.         .blackcell{
  9.             display: inline-block;
  10.             width: 50px;
  11.             height: 50px;
  12.             background: black;
  13.         }
  14.         .whitecell{
  15.             display: inline-block;
  16.             width: 50px;
  17.             height: 50px;
  18.             background: white;
  19.         }
  20.     </style>
  21. </head>
  22. <body>
  23.     <div id="board"></div>
  24.  
  25.     <script>
  26.         function board(size){
  27.             let result = "";
  28.             for(let i = 0; i < size; i++){
  29.                 result += "<div>\n";
  30.                 for(let j = 0; j < size; j++){
  31.                     let cls = ((i+j)%2 == 0) ? "blackcell" : "whitecell";
  32.                     result += "<div class=\"" + cls + "\"></div>\n";
  33.                 }
  34.                 result += "</div>\n";
  35.             }
  36.             return result;
  37.         }
  38.  
  39.         document.getElementById("board").innerHTML = board(8);
  40.     </script>
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment