I would like to write a javascript code such that the boards appears as it is in this image:
1
This is my code so far:
function draw() {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var x, y;
for (y=0; y<100; y+=10) {
for (x=0; x<100; x+=5) {
if ((x+y)%10 == 0) {
ctx.fillStyle = "black";
}
else {
ctx.fillStyle = "white";
}
ctx.fillRect(x, y, 10, 10);
}
}
}
As of now, it only displays vertical lines. What changes do I need to make, in order for it to appear like the image?
You should divide your x value by the increment (10) and check its modulo 2 :