‘X’ changes to ‘O’ and vice versa | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

14th Oct 2022, 5:22 AM
Triz
Triz - avatar
13 Answers
+ 4
if (shape.innerHTML!="" || gameEnded) return;
14th Oct 2022, 6:52 AM
SoloProg
SoloProg - avatar
+ 3
if (event.target.innerHTML !="" && !gameEnded) return;
14th Oct 2022, 6:42 AM
Arturop
Arturop - avatar
+ 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
14th Oct 2022, 7:23 AM
SoloProg
SoloProg - avatar
+ 2
Good job
14th Oct 2022, 6:15 PM
SoloProg
SoloProg - avatar
+ 2
Triz Great suggestions from SoloProg. One suggestion is to fix the css so it would be resized when viewed on the phone. Most Sololearners use the app and the board is too big for small screens.
16th Oct 2022, 2:00 AM
Bob_Li
Bob_Li - avatar
+ 1
Triz , good game body { user-select: none; /* add it */ }
14th Oct 2022, 6:56 AM
SoloProg
SoloProg - avatar
+ 1
It works now. Thank you! Arturop SoloProg
14th Oct 2022, 6:56 AM
Triz
Triz - avatar
+ 1
SoloProg I’ll check it out. Thanks again!
14th Oct 2022, 1:41 PM
Triz
Triz - avatar
+ 1
SoloProg when i add the JavaScript to VS code, the board doesn’t load
14th Oct 2022, 2:13 PM
Triz
Triz - avatar
+ 1
Triz , I think you forgot to add "script" tag in html code.
14th Oct 2022, 3:05 PM
SoloProg
SoloProg - avatar
+ 1
SoloProg I have the script tag.
14th Oct 2022, 3:19 PM
Triz
Triz - avatar
+ 1
I cannot help you because i cannot try it and cant run the code
14th Oct 2022, 3:34 PM
SoloProg
SoloProg - avatar
+ 1
SoloProg i fixed it
14th Oct 2022, 5:58 PM
Triz
Triz - avatar