Getting Problem at TicTacToe

Hello There,
So i am trying to build a TicTacToe from scratch. According to my code when there are 7 inputs, in the game, it returns different answers, sometimes it checks right or sometimes it gives wrong result. The following screenshot will help you to understand the problem exactly

The wrong one
The right one

Here is the link for my code Please review my code and help me to find my mistake
Github Repo

Hi there!
I just looked through your code real quick. Shouldn’t you be using which_game variable name instead of game in your getData function logic?

function getData(data, which_game, player) {
var box = data.getAttribute(“data-box”);
//console.log(box);
if (!game.isClicked) { // which_game ?
game.cross.push(box); // which_game ?
} else if (game.isClicked) { // which_game ?
game.round.push(box); // which_game ?
}

yeah its just test basis… I will refactor the code when the project is complete…can you find the error what i asked for?

Your logic in this part needs to be checked again:
game.winning_array.map(v => {

  if (
    comp
      .join("")
      .split("")
      .some(val => {
        return v.indexOf(val) == -1;
      })

the some function on the comp array is returning true even if one of the value matches any value in the winning array.Maybe you have to make a check that 3 values should definitely be there to be true.
Resource on some function:
https://www.w3schools.com/jsref/jsref_some.asp
If are not able to create a logic, I can try to help.

so first i have to check in comp array that there should be 3 values to be checked with the inputting array. i can understand your aspect … but cant get how to build the logic. Any help with that plz… :slight_smile:

I am trying to use array.prototye.every() function to build the logic. Why don’t you try that as well in the meanwhile.

i also tried that but it returns same result…:hushed::hushed:

Any other methods that we can make use of??

I actually used it and got the logic. Let me share the code.

//getting errors from here

} else if (arr.length > 3) {

let check = false;

game.winning_array.map(v => {
    
  if(v.every(elem => comp.indexOf(elem) > -1)){
    
      document.getElementById("output").innerHTML = `${player} Wins`;
      console.log("Player Wins");
      check = true;
    }
 
});

if(check)
  document.getElementById("output").innerHTML = `${player} Wins`
else
  document.getElementById("output").innerHTML = ` Draw`

} else return false;

But the problem is, your code doesn’t stop at the end of game. It stops and returns “Draw” because of the check( if arr.length>3) at the top. Can you try thinking of another logic ?

Thanks for this help i will implement this and let you know how long it goes…:blush::blush::slight_smile:

Great!
From here, you need to see that your game stops when a player wins and should continue if player doesn;t win until the end of chances left.

yupp i will work on it…Thanks again