samedi 23 mai 2020

Unable to set proper conditional statement

I wrote the following if condition so that if the the td is empty the innerHTML should be '0'. But even when the innerHTML is "X" and not ''(empty), it still change the (X) to 0.

The first condition that turn it to X is:

  zero.innerHTML='X';
  w=1;
}
else if(w==2 && one.innerHTML==''){
one.innerHTML='X';
w=1;
}
else if(w==2 && two.innerHTML==''){
two.innerHTML='X';
w=1;
}

But still:

if(w==1 && zero.innerHTML==''){
zero.addEventListener('click',function(){
zero.innerHTML='O';
w=2;
})
}
if(w==1 && one.innerHTML==''){
one.addEventListener('click',function(){
one.innerHTML='O';
w=2;
})
}
if(w==1 && two.innerHTML==''){
two.addEventListener('click',function(){
two.innerHTML='O';
w=2;
})
}

Changes the 'X' to '0'.

Please any help will be appreciated because I'm confused

Aucun commentaire:

Enregistrer un commentaire