Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- body{
- background: #a3cfe0;
- }
- .blackcell{
- display: inline-block;
- width: 50px;
- height: 50px;
- background: black;
- }
- .whitecell{
- display: inline-block;
- width: 50px;
- height: 50px;
- background: white;
- }
- </style>
- </head>
- <body>
- <div id="board"></div>
- <script>
- function board(size){
- let result = "";
- for(let i = 0; i < size; i++){
- result += "<div>\n";
- for(let j = 0; j < size; j++){
- let cls = ((i+j)%2 == 0) ? "blackcell" : "whitecell";
- result += "<div class=\"" + cls + "\"></div>\n";
- }
- result += "</div>\n";
- }
- return result;
- }
- document.getElementById("board").innerHTML = board(8);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment