chessboard using javascript

In this short post we will see how to create a chessboard using JavaScript.

First lets begin by creating an index.html file.

Canvas tag not supported

In our tag we have defined a canvas element with id=canvas and width and height equal to 280px and we are importing our script.js file which has the main code for drawing on the canvas.

  var c=document.getElementById("canvas");
  var ctx=c.getContext("2d");

for(var i=0;i<8;i++) {
    for(var j=0; j<8;j=j+2) {
      start_position = j * 35;
          start_position = (j+1) * 35;
      ctx.fillRect(start_position,(i*35) ,35,35);

Related Posts