+ 2
âXâ changes to âOâ and vice versa
If I click on the Oâs it changes to X and vice versa. Iâm trying to prevent cheating in this game and I added a code (in JavaScript file below comment: prevents cheating) but itâs not working properly. Could someone please assist me? https://code.sololearn.com/W31nOKfdzzj7/?ref=app
13 Respostas
+ 4
if (shape.innerHTML!="" || gameEnded) return;
+ 3
if (event.target.innerHTML !="" && !gameEnded) return;
+ 2
Triz , To improve your game
//Determining Winner
WhoWon(lastPlayer);
WhoWon = (lp) => {
if ((arr[0]===lp && arr[1]===lp && arr[2]===lp) ||
(arr[3]===lp && arr[4]===lp && arr[5]===lp) ||
(arr[6]===lp && arr[7]===lp && arr[8]===lp) ||
(arr[0]===lp && arr[3]===lp && arr[6]===lp) ||
(arr[1]===lp && arr[4]===lp && arr[7]===lp) ||
(arr[2]===lp && arr[5]===lp && arr[8]===lp) ||
(arr[0]===lp && arr[4]===lp && arr[8]===lp) ||
(arr[2]===lp && arr[4]===lp && arr[6]===lp) )
{
announcer.classList.add("you-won");
announcer.innerHTML= `Congratulations! ${lp} is the winner!`;
gameEnded=true;
}
}
https://www.sololearn.com/compiler-playground/WSogXQxGni0B
+ 2
Good job
+ 1
Triz , good game
body {
user-select: none; /* add it */
}
+ 1
SoloProg Iâll check it out. Thanks again!
+ 1
SoloProg when i add the JavaScript to VS code, the board doesnât load
+ 1
Triz ,
I think you forgot to add "script" tag in html code.
+ 1
SoloProg I have the script tag.
+ 1
I cannot help you because i cannot try it and cant run the code
+ 1
SoloProg i fixed it