# \[SOLVED\]-Tic Tac Toe reset problems

**URL:** <https://forum.freecodecamp.org/t/solved-tic-tac-toe-reset-problems/94102>\
**Category:** General\
**Created:** [March 6, 2017, 5:20pm UTC](https://forum.freecodecamp.org/t/solved-tic-tac-toe-reset-problems/94102 "2017-03-06T17:20:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![laguno](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/laguno/32/23725_2.png) [@laguno](https://forum.freecodecamp.org/u/laguno)\
**Post date:** [March 6, 2017, 5:20pm UTC](https://forum.freecodecamp.org/t/solved-tic-tac-toe-reset-problems/94102/1 "2017-03-06T17:20:01Z")

</div>

Hi guys… it ii over 1 week i start this challenge and i think this is the most difficult since i start with FCC…  
I still have problem with my Computer AI…but what i dont’know it this:  
if i play a 2 players game everything its ok when i reset for next match…but if i play against computer, when i click “next game” button after a match it start with the last games moves…even if my reset function its called…and it reset every array exept the possible wins arrays…  
this is my code…someone can help me???

> **[tic tac toe freeCodeCamp](https://codepen.io/Laguno/pen/mRZvOv?editors=0011)**
>
> ...

---

<div class="post-metadata">

**Author:** ![KKOL](https://avatars.discourse-cdn.com/v4/letter/k/9fc348/32.png) [@KKOL](https://forum.freecodecamp.org/u/KKOL)\
**Post date:** [March 6, 2017, 6:18pm UTC](https://forum.freecodecamp.org/t/solved-tic-tac-toe-reset-problems/94102/2 "2017-03-06T18:18:51Z")

</div>

Hi Laguno, I don’t exam in depth your code, but accordingly to what i’ve seen when fired the reset ‘button’ after playing against the computer, i will say, you probably not clear the computers moves. In which variable do you store the computer moves or playes moves? .  
And now, you are using setInterval, i will recommend to use setTimeout instead which excuted just once. setInterval call your function repeatedly. So when you reset the game, and you want now the computer to play first, setInterval just call the computer every second and put all the previous stored position without waiting you to pay.

---

<div class="post-metadata">

**Author:** ![JohnL3](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/johnl3/32/16459_2.png) [@JohnL3](https://forum.freecodecamp.org/u/JohnL3)\
**Post date:** [March 6, 2017, 7:45pm UTC](https://forum.freecodecamp.org/t/solved-tic-tac-toe-reset-problems/94102/3 "2017-03-06T19:45:17Z")

</div>

when your game resets it goes through your reset function then goes in the disegnaSegno function and jumps back and forth through the code below … and on each iteration it adds the computor moves to the screen … so debug these and you find out whats going on that you dont want to happen

````auto
  $("div.quadrato").each(function(element) {
    if ($(this).text() == item.toString()) {
      var c = $(this);
      setInterval(function() {
        $(c).addClass(segno_computer);
      }, 1000);
    }
  });```

line num 27) function computerMove() { 
line 35)
 ```if (checkAvailability(5)) {
      setInterval(function() {
        $("#cinque").addClass(segno_computer);
      }, 1000);```
````

---

<div class="post-metadata">

**Author:** ![laguno](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/laguno/32/23725_2.png) [@laguno](https://forum.freecodecamp.org/u/laguno)\
**Post date:** [March 6, 2017, 8:47pm UTC](https://forum.freecodecamp.org/t/solved-tic-tac-toe-reset-problems/94102/4 "2017-03-06T20:47:37Z")

</div>

thank you very much to @KKOL and @JohnL3…the problem was the setInterval insted setTimeout…now the reset works …  
I just have to finish the AI and after i can start with the next challenge…for now my AI its very stupid…

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 9:36am UTC](https://forum.freecodecamp.org/t/solved-tic-tac-toe-reset-problems/94102/5 "2021-01-17T09:36:53Z")

</div>

Closed on January 17, 2021, 9:36am UTC


