+ 2
What is a problem of this code please tell me that my pleasure ??
4 ответов
+ 4
thanks a lot all of you
+ 3
The bug is in the checkMove().
You are checking the whole boxes with each other, not the signs in them .
+ 2
in line 39 instead of number 5 write number 6
In the checkMove () function, use document.getElementById (...). TextContent;
in line 33 remove the second brackets
in the winner () function instead of the letter "x" use the variable "sign"
the winner () function must be called before the checksign () function
line: disp.innerHTML = sign + "turn's ...";
and the line: turn.innerText = sign; - should not be performed after someone wins
+ 2
after all the fixes, the code will look like this:
let sign = "X";
let disp =document.getElementById("player");
function print(number){
let turn =document.getElementById("r"+ number );
if(turn.innerText == "" && !winner()){
turn.innerText = sign;
if (!winner()){
checksign();
disp.innerHTML =sign + " turn's..";
}
}
}
function checksign(){
if (sign== "X")sign="O" ;
else sign = "X" ;
}
function getbox(no){
return document.getElementById("r"+no).textContent;
}
function checkmove(a,b,c,m){
if(getbox(a)==m && getbox(b)==m && getbox(c)==m )
return true;
else return false;
}
function winner() {
if (checkmove(1,2,3,sign)||
checkmove(4,5,6,sign)||
checkmove(7,8,9,sign)||
checkmove(1,4,9,sign)||
checkmove(3,4,7,sign)||
checkmove(1,4,7,sign)||
checkmove(2,4,8,sign)||
checkmove(3,6,9,sign)){
disp.innerHTML = sign + " you won ..😃😃😃";
return true;
}
else return false;
}