Tic-Tac-Toe Switch Trouble [Solved]

Tic-Tac-Toe Switch Trouble [Solved]
0

#1

Hello all!

I am working on Tic-Tac-Toe and am using a Minimax function to find the best move for the AI. However, when I try to add the function to my board array, the array is not properly picking it up and, for some reason, my case statement is also not accepting the number that my function returns.

Can anyone explain why this is happening? I have put the specific case below and a link to the full project as well:

      var bestSpot = decision(board, player2Symbol);
      console.log("new");
      console.log(bestSpot.index);
      board[bestSpot.index] = player2Symbol;
      console.log(player2Symbol);
      console.log(board[bestSpot.Index]);
      console.log(board);
      console.log(typeof bestSpot.index);
      switch(bestSpot.Index) {
        case 0: $("#spot1").html(player2Symbol);
          console.log("spot1");
          break;
        case 1: $("#spot2").html(player2Symbol);
          break;
        case 2: $("#spot3").html(player2Symbol);
          break;
        case 3: $("#spot4").html(player2Symbol);
          break;
        case 4: $("#spot5").html(player2Symbol);
          break;
        case 5: $("#spot6").html(player2Symbol);
          break;
        case 6: $("#spot7").html(player2Symbol);
          break;
        case 7: $("#spot8").html(player2Symbol);
          break;
        case 8: $("#spot9").html(player2Symbol);
          break;
        default: console.log("test1");
          break;

Project link: http://codepen.io/ZZBrent/pen/gWQvwg?editors=1111

UPDATE: Solved this! Sorry, must be a lack of sleep. I capitalized some of the index calls. Silly me :confused: