Changed around line 1
+ const sudokuGrid = document.getElementById('sudokuGrid');
+ const checkButton = document.getElementById('checkButton');
+ const resultMessage = document.getElementById('resultMessage');
+ const difficultyButtons = document.querySelectorAll('.buttons button');
+
+ const puzzles = {
+ simple: [
+ [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]
+ ],
+ normal: [
+ [0, 0, 0, 0, 0, 0, 6, 8, 0],
+ [0, 0, 0, 0, 7, 3, 0, 0, 9],
+ [3, 0, 9, 0, 0, 0, 0, 4, 5],
+ [4, 9, 0, 0, 0, 0, 0, 0, 0],
+ [8, 0, 3, 0, 5, 0, 9, 0, 2],
+ [0, 0, 0, 0, 0, 0, 0, 3, 6],
+ [9, 6, 0, 0, 0, 0, 3, 0, 8],
+ [7, 0, 0, 6, 8, 0, 0, 0, 0],
+ [0, 2, 8, 0, 0, 0, 0, 0, 0]
+ ],
+ complicated: [
+ [0, 0, 0, 6, 0, 0, 4, 0, 0],
+ [7, 0, 0, 0, 0, 3, 6, 0, 0],
+ [0, 0, 0, 0, 9, 1, 0, 8, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 5, 0, 1, 8, 0, 0, 0, 3],
+ [0, 0, 0, 3, 0, 6, 0, 4, 5],
+ [0, 4, 0, 2, 0, 0, 0, 6, 0],
+ [9, 0, 3, 0, 0, 0, 0, 0, 0],
+ [0, 2, 0, 0, 0, 0, 1, 0, 0]
+ ],
+ 'very-complicated': [
+ [0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 3, 0, 8, 5],
+ [0, 0, 1, 0, 2, 0, 0, 0, 0],
+ [0, 0, 0, 5, 0, 7, 0, 0, 0],
+ [0, 0, 4, 0, 0, 0, 1, 0, 0],
+ [0, 9, 0, 0, 0, 0, 0, 0, 0],
+ [5, 0, 0, 0, 0, 0, 0, 7, 3],
+ [0, 0, 2, 0, 1, 0, 0, 0, 0],
+ [0, 0, 0, 0, 4, 0, 0, 0, 9]
+ ]
+ };
+
+ function createGrid(puzzle) {
+ sudokuGrid.innerHTML = '';
+ for (let i = 0; i < 9; i++) {
+ for (let j = 0; j < 9; j++) {
+ const input = document.createElement('input');
+ input.type = 'text';
+ input.maxLength = 1;
+ input.value = puzzle[i][j] === 0 ? '' : puzzle[i][j];
+ if (puzzle[i][j] !== 0) {
+ input.disabled = true;
+ input.classList.add('fixed');
+ }
+ sudokuGrid.appendChild(input);
+ }
+ }
+ }
+
+ function checkSolution() {
+ const inputs = sudokuGrid.querySelectorAll('input');
+ let isValid = true;
+ inputs.forEach(input => {
+ if (input.value === '') isValid = false;
+ });
+ if (isValid) {
+ resultMessage.textContent = 'Congratulations! You solved it!';
+ resultMessage.style.color = 'var(--success-color)';
+ } else {
+ resultMessage.textContent = 'Keep trying! You can do it!';
+ resultMessage.style.color = 'var(--error-color)';
+ }
+ }
+
+ difficultyButtons.forEach(button => {
+ button.addEventListener('click', () => {
+ const difficulty = button.dataset.difficulty;
+ createGrid(puzzles[difficulty]);
+ resultMessage.textContent = '';
+ });
+ });
+
+ checkButton.addEventListener('click', checkSolution);
+
+ // Initialize with simple puzzle
+ createGrid(puzzles.simple);