Basic tic-tac-toe JavaScript -


i struggling add option of taking turns in program want do. need add "x" wherever player clicks , second click add "o". when run code "x" everytime click it. how change this?

 function x() {      this.innerhtml = "x";  }   function o() {      this.innerhtml = "o";  }   function xdo() {      (i = 1; <= 9; i++) {          document.getelementbyid("cell" + i).onclick = x;      }  }   function odo() {      (i = 1; <= 9; i++) {          document.getelementbyid("cell" + i).onclick = o;      }  }   var turn = true;   if (turn == true) {      xdo();      turn == false;   } else if (turn == false) {      odo();      turn == true;      } 

in below code snippet..

if(turn==true) { xdo(); turn==false; // assignment operator should used turn =false  } else if(turn ==false) {  odo(); turn==true; // assignment operator should used turn =true  } 

comparison operator(==) used, should have been assignment operator (=)


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -