Tool Request: call_S8uZEj0erqZhzVFRLD4ODMU5 - create_file
{"content":"const cells = document.querySelectorAll('.cell');\nconst restartButton = document.getElementById('restartButton');\n\nlet isXTurn = true;\n\n// All possible winning combinations\nconst winningCombinations = [\n [0, 1, 2],\n [3, 4, 5],\n [6, 7, 8],\n [0, 3, 6],\n [1, 4, 7],\n [2, 5, 8],\n [0, 4, 8],\n [2, 4, 6]\n];\n\n// Handle a cell click event\nfunction handleClick(event) {\n const cell = event.target;\n const currentPlayer = isXTurn ? 'X' : 'O';\n\n // if cell is already taken, ignore click\n if (cell.textContent !== '') {\n return;\n }\n\n // Place the player's mark\n cell.textContent = currentPlayer;\n\n // Check for win\n if (checkWin(currentPlayer)) {\n setTimeout(() => {\n alert(`${currentPlayer} wins!`);\n restartGame();\n }, 100);\n return;\n }\n\n // Check for draw\n if (checkDraw()) {\n setTimeout(() => {\n alert('Draw!');\n restartGame();\n }, 100);\n return;\n }\n\n // Swap turns\n isXTurn = !isXTurn;\n}\n\n// Check if the current player has any winning combination\nfunction checkWin(player) {\n return winningCombinations.some(combination => {\n return combination.every(index => {\n return cells[index].textContent === player;\n });\n });\n}\n\n// Check if all cells are filled and no empty cell left\nfunction checkDraw() {\n return Array.from(cells).every(cell => cell.textContent !== '');\n}\n\n// Reset the game board\nfunction restartGame() {\n cells.forEach(cell => cell.textContent = '');\n isXTurn = true;\n}\n\n// Attach click event listeners to each cell\ncells.forEach(cell => cell.addEventListener('click', handleClick));\n\n// Attach click event listener to the restart button\nrestartButton.addEventListener('click', restartGame);\n","file_name":"game.js"}