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
Post a Comment