0
votes

I'm using ternary expression for player change, and it works fine. ESLint gives me this error - https://eslint.org/docs/rules/no-unused-expressions

activePlayer === 0 ? (activePlayer = 1) : (activePlayer = 0);

Could you help me make my code better?

1
activePlayer = activePlayer === 0 ? 1 : 0? Or just activePlayer = !activePlayer, and stop messing around with numbers.jonrsharpe
activePlayer can be boolean?Carlo Corradini
You're using ternary operator as it it was an if conditional, which is kind of confusing. Also, it feels as if activePlayer should actually be a boolean variable rather than an integer (unless it's a multiplayer game and it actually represents a player number).Álvaro González

1 Answers

0
votes
activePlayer =  activePlayer === 0 ? 1 : 0 ;