I find it puzzling how the == 0
is used in conjunction with the remainder
part of the code. Take for instance (4+4) % 2 == 0
, it seems like it should evaluate to 4, but this piece of code actually generates outputs like true
, false
, true
, false
, and so on.
var size = 8;
var board = "";
for (var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
if ((x + y) % 2 == 0)
board += " ";
else
board += "#";
}
board += "\n";
}
console.log(board);