update
This commit is contained in:
parent
8521834c15
commit
c38f48b727
4 changed files with 185 additions and 0 deletions
38
JavaScript Solution/script.js
Normal file
38
JavaScript Solution/script.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
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;
|
Loading…
Add table
Add a link
Reference in a new issue