-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
33 lines (29 loc) · 970 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Define the initial Sudoku grid
const initialGrid = [
[5, 3, 0, 0, 7, 0, 0, 0, 0],
[6, 0, 0, 1, 9, 5, 0, 0, 0],
[0, 9, 8, 0, 0, 0, 0, 6, 0],
[8, 0, 0, 0, 6, 0, 0, 0, 3],
[4, 0, 0, 8, 0, 3, 0, 0, 1],
[7, 0, 0, 0, 2, 0, 0, 0, 6],
[0, 6, 0, 0, 0, 0, 2, 8, 0],
[0, 0, 0, 4, 1, 9, 0, 0, 5],
[0, 0, 0, 0, 8, 0, 0, 7, 9]
];
// Function to render the Sudoku grid
function renderGrid(grid) {
const cells = document.querySelectorAll('.cell');
let index = 0;
for (let row = 0; row < 9; row++) {
for (let col = 0; col < 9; col++) {
cells[index].textContent = grid[row][col] === 0 ? '' : grid[row][col];
index++;
}
}
}
// Function to initialize the Sudoku game
function initializeGame() {
renderGrid(initialGrid);
}
// Call initializeGame when the DOM content is loaded
document.addEventListener('DOMContentLoaded', initializeGame);