+ 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 odpowiedzi
+ 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