How to delay javascript until html updates ?

I'm not sure I understand what you say about "new symbols not showing", but there are a number of problems in the code.

  • The code in the repo and the code in the live version are not the same. So the link to the repository is useless. It does contain some errors, but I will ignore them as it is not the code you're actually running. I'll only say this about the code in the repo: That wait function is a terrible, terrible idea.

  • In lines 13-17 of script.js:

    if ((ai)&&(occupied<9)) {
        AI()
    };
    update();
    winCheck();
    

That is, you let the "ai" player make its move before checking if the human player has won. This is noticed because when I won, an additional move from the "ai" player appears on the board. (Notice that in the repo this has changed and you only let the player play if no player has won yet)

  • There's a problem in the ai function in the loop in line 66. The problem is in line 67, to be precise: aiChoice=Math.floor(Math.random() * 6) + 1 ;. If the ai function has to resort to this loop to pick up a random empty cell, but you have the "bad luck" that cell 1 to 6 have all been played, the loop will be stuck there forever and the page will freeze. Did you notice it? You're generating random numbers only from 1 to 6, instead of from 1 to 9.
/r/javascript Thread