What's wrong?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

25th Feb 2023, 9:35 PM
Krish Tiwari
Krish Tiwari - avatar
11 Answers
+ 2
This code is incomplete. Please show your complete code – put it in a script on sololearn playground.
25th Feb 2023, 9:37 PM
Lisa
Lisa - avatar
+ 2
Go to Code section, click +, select web, put code in Javascript tab, save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
25th Feb 2023, 9:39 PM
Lisa
Lisa - avatar
+ 2
There is no table in your html?
25th Feb 2023, 10:52 PM
Lisa
Lisa - avatar
+ 1
Did you write the code yourself? Did you copy it from somewhere? Line 10 clearly refers to an html element. There is no such element in your html tab. You need to provide the complete code.
26th Feb 2023, 5:50 PM
Lisa
Lisa - avatar
+ 1
Chat GPT did a decent job overall. However, if you learn to code, you can help identify and fix any potential issues that may arise. I was able to make some modifications using the fundamentals I learned on SoloLearn, which helped me get the code to work. If there are parts of the code that you don't understand, Chat GPT can add comments and provide thorough explanations for each section. Or you can ask the community. Enjoy! There may still be errors. If anyone wants to help fix them. Go right ahead! https://code.sololearn.com/Wq45Wg31d452/?ref=app
28th Feb 2023, 12:49 AM
Chris Coder
Chris Coder - avatar
0
How to do that
25th Feb 2023, 9:38 PM
Krish Tiwari
Krish Tiwari - avatar
25th Feb 2023, 10:05 PM
Krish Tiwari
Krish Tiwari - avatar
0
Any help
25th Feb 2023, 10:08 PM
Krish Tiwari
Krish Tiwari - avatar
0
What does it mean now the code is in js
26th Feb 2023, 5:43 PM
Krish Tiwari
Krish Tiwari - avatar
0
This code is made by useless chat gpt
26th Feb 2023, 7:23 PM
Krish Tiwari
Krish Tiwari - avatar
0
Sorry if I wasted u r time
26th Feb 2023, 7:24 PM
Krish Tiwari
Krish Tiwari - avatar