Problem in JavaScript Tic-Tac-Toe game. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Problem in JavaScript Tic-Tac-Toe game.

Hey guys. I have written this code - https://code.sololearn.com/WloTe90GT7e3/#html. But there is one problem: When I click one a new button, previous button losts it's cross. Maybe somebody knows how to fix it? I'll really apreciate any help.

20th May 2018, 6:07 PM
Evil Dog
Evil Dog - avatar
1 Answer
+ 3
I got it. https://code.sololearn.com/Wzoz6UFdb3zc/#js The problem is that you are using the same text nodes (one X and one O) each time you call the play() function. This means that when you append window.compNode or window.playerNode to a <div>, it is removed from the one it was previously in. What I did to fix it was I made compNode and playerNode functions that return a new text node each time it is called. Now when you append playerNode() to a <div> it makes a new one there, instead of moving the same one around. Also, I made it so that only the 'data' property of each TextNode object is added to the cells array so it is easier to track. Hope this helped :)
21st May 2018, 12:53 PM
Just A Rather Ridiculously Long Username