Tic Tac Toe Frustration; Please Help

Please help. I’ve been staring at this code and changing things around for two days, and I still can’t even get the two non-AI players portion to work! I really need some objectivity.

I absolutely cannot figure out why:

  1. Whether X or O is chosen, the first square clicked on the grid displays X
  2. Only two Os are able to be marked to the grid before each remaining mark defaults to X

Codepen

about 1

inside $(".O").click(function() {
there is code like
player1.symbol = “O”;
which makes player 1 symbol o
player1.your_turn = false;
but because of this 1st turn of the game is players 2’s turn so it display x

I see. Thank you. I’d misplaced my basic understanding of the game’s rules. X always goes first, so you are selecting for the “other person” when you choose O and the first square marked is X.

That takes care of the first issue. What about the second?

about 2 i actually didnt understand the problem :confused:

Well, when you try to play Human vs. Human, what happens?
Say you’re X. You go, O goes, you go, O goes, you go, then O can’t go anymore.

in line 258
var check_o = wins.array[i].every(function(val) {
return arr2.indexOf(val) >= 0;
});

it should be like
var check_o = wins_array[i].every(function(val) {
return arr2.indexOf(val) >= 0;
});

you missplace _ with .

Oh shit! Thanks so much! How’d you get that so fast? :grinning:

i checked the console there is a rafernece error for win

My console wasn’t showing any errors. Going to have to figure out why.
Thanks again! I had little hope of getting this solved tonight. FCC Forum is great.

Oh, you mean browser console, not Codepen’s. Codepen’s doesn’t display any errors. I guess I didn’t realize that.

it shouldn’t give any error now as you change the code but previously i get error like this

best of luck for tonight :slight_smile:

just a heads up if you plan to implement minmax algorithm for ai in human vs computer section it might be very hard and might take time then usual just dont give up