One strategy you could use for this is to see if there is an existing value for innerHTML before you set it to an X or O. Only update it to X or O if it’s currently blank, for example.
As you build this game out, you’ll see you need to handle other edge cases too. Like if you do check for an existing value and only place the X or O if they click on an empty cell, you’ll need to make sure you don’t count that as their turn.
Given the amount of topics you are making, I recommend to to make a codepen (or use github, or something like that) so we can see your whole codebase and progress.
Now we get bits and pieces every time, which doesn’t really tempt to help you. Maybe that is just me, that is possible. Its just easier to help if we have all the information
Just an idea.
@selectall is a good suggestion, except that DOM manipulation/interaction is expensive.
I would also create a multi-dimensional array to represent your board in JavaScript,which you could use to check if the move is valid, and then update your associative array and board accordingly
@stetim94 That’s absolutely a good suggestion to create a multi-dimensional array to represent the board. Ultimately that’s one of the things that would be necessary as this project progresses in order to efficiently evaluate the win/loss conditions anyway.
exactly, later even more. Maybe I guided too much already towards the right solution. Sometimes running into this issues/problems yourself can be a really useful learning experience
glad to hear I am not the only one who thinks that way