What's wrong??
// Initialize variables var board = [ ["", "", ""], ["", "", ""], ["", "", ""] ]; var currentPlayer = "X"; // Get all cells var cells = document.getElementsByTagName("td"); // Add click event listener to each cell for (var i = 0; i < cells.length; i++) { cells[i].addEventListener("click", function() { // Get row and column of clicked cell var row = this.id[4]; var col = this.id[5]; // If cell is already occupied or game is over, do nothing if (board[row][col] !== "" || isGameOver(board)) { return; } // Update board and UI board[row][col] = currentPlayer; this.innerHTML = currentPlayer; // Check for winner and switch player if (hasWinner(board)) { alert(currentPlayer + " has won!"); } else { currentPlayer = currentPlayer === "X" ? "O" : "X"; } }); } // Check if the game is over function isGameOver(board) { var flatBoard