A
A
Artem Vedishchev2018-02-14 00:45:16
JavaScript
Artem Vedishchev, 2018-02-14 00:45:16

How to catch an error in Tic Tac Toe?

There is a code for the game "Tic-Tac-Toe"
https://codepen.io/ArtemVedischev/pen/oEzwOa?edito...
I wrote it myself, please do not scold too much. I am just learning.

In a single game, sometimes the check for empty fields fails, the computer makes a move to an already occupied field.
Checking for empty fields occurs in the getEmptySquare() function. And based on this, the field for the move is selected.
What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-02-14
@Artem-V

And if so?

function getEmptySquare() { // почему get, если функция ничего не возвращает?
                                        // и почему square, если их там не один?
    emptySquare = []
    $('.item').each(function(){
      if (!this.textContent.length) {
        emptySquare.push(this.id)
      }
    })
    console.log('emptySquare:', emptySquare) 
}
In general, it’s cool for a start, but for good, more than half of it must be mercilessly thrown away, and the rest must be redone, and then added more.
A lot of duplication, strange names of variables and functions, their ambiguous behavior, and the logic let us down in places.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question