Tic-Tac-Toe Help and code improvement

Tic-Tac-Toe Help and code improvement
0

#1

Hi everyone!

I need a bit of help on the tic-tac-toe game.
so right now, the player is prompted to select a character between X and O. Whatever the player chooses, they will always be first (I’m fixing that later). The next step is to click on a tile and then it will trigger a random number generator for the PC’s turn. The problem is, that its always trying to generate a number so its in a loop!

I tried to add clearInterval() but it didn’t fix the issue. the reason behind using a timer is so that it will make the pc look like its “thinking”.

here’s a link to the pen.

thanks!
Kevin


#2

So, 2 things:

  1. Look into setTimeout–it’s similar to setInterval, but instead of making something happen every time interval, it’ll make something happen just once after a set amount of time.
  2. For future reference, setInterval returns some value. To clear a setInterval, you can use this returned value as follows:
var someVariableNameHere = setInterval(function({}), 1000);
// ...stuff happens here, presumably
clearInterval(someVariableNameHere);