function getBoardFromInputs() { let sudokuInputs = document.querySelectorAll("#sudoku-board input"); let sudokuBoard = []; sudokuInputs.forEach((input, index) => { let rowIndex = Math.floor(index / 9); let colIndex = index % 9; if (!sudokuBoard[rowIndex]) { sudokuBoard[rowIndex] = []; } sudokuBoard[rowIndex][colIndex] = parseInt(input.value) || 0; }); return sudokuBoard; } function initializeBoard() { let table = document.getElementById("sudoku-board"); for (let i = 0; i < 9; i++) { let row = table.insertRow(); for (let j = 0; j < 9; j++) { let cell = row.insertCell(); let value = board[i][j]; let input = document.createElement("input"); input.type = "text"; input.maxLength = 1; input.value = value === "." ? "" : value; input.addEventListener("input", function () { // Update the value in the board1 array when user changes input board[i][j] = this.value === "" ? "." : this.value; }); cell.appendChild(input); } } } window.onload = initializeBoard;