I am trying to print a 9x9 2D JavaScript array in a grid format and I cannot get a line break to concatenate into a printable string. It prints the entire array in a single line when I want to print in a square grid. Here is the code:
function printBoard(board) {
var toPrint = "";
for (var i = 0; i < board.length; i++) {
for (var j = 0; j < board.length; j++) {
toPrint += board[i][j] + " ";
}
toPrint += "\n";
}
document.getElementById("printBoard").innerHTML = toPrint;
}
Anyone see something obvious I'm not seeing? I'm new to JavaScript so take it easy on me if its an obvious error, but I'm not just seeing it. Does the innerHTML function not print multiple lines? The HTML side of it is very simple:
<p id="printBoard"></p>
– ASDFGerte Aug 09 '18 at 23:45
tag https://jsfiddle.net/708rw1zf/1/ – programming for fun Aug 09 '18 at 23:46