I understand most of the code, but I am unsure why in the if statement you add x
and y
. What does this do?
Also, what does the board += "\n";
accomplish?
let size = 8;
let board = "";
for (let y = 0; y < size; y++) {
for (let x = 0; x < size; x++) {
if ((x + y) % 2 == 0) {
board += " ";
} else {
board += "#";
}
}
board += "\n";
}
console.log(board);