I have the following code:
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);
document.write(board);
<h1 style="text-align: center; color: rebeccapurple;">Chess Board</h1>
console.log
output:
document.write
output:
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Why do they output different results?
` to see a line break in HTML – Anurag Srivastava Feb 13 '21 at 09:33