试图创建一个由javascript驱动的井字游戏。但是,我似乎无法使我的胜利检查功能正常工作,因为传递给if块的布尔条件不能与||一起正常工作。运算符。
console.log((currGameGrid[0]==currGameGrid[1])&&(currGameGrid[1]==currGameGrid[2]))
为我返回了true,但是if代码块仍然无法运行。
if ( //Row win
( (currGameGrid[0]==currGameGrid[1])&&(currGameGrid[1]==currGameGrid[2]) )||
( (currGameGrid[3]==currGameGrid[4])&&(currGameGrid[4]==currGameGrid[5]) )||
( (currGameGrid[6]==currGameGrid[7])&&(currGameGrid[7]==currGameGrid[8]) )||
// Column win
( (currGameGrid[0]==currGameGrid[3])&&(currGameGrid[3]==currGameGrid[6]) )||
( (currGameGrid[1]==currGameGrid[4])&&(currGameGrid[4]==currGameGrid[7]) )||
( (currGameGrid[2]==currGameGrid[5])&&(currGameGrid[5]==currGameGrid[8]) )||
// Diagonal L to R
( (currGameGrid[0]==currGameGrid[4])&&(currGameGrid[4]==currGameGrid[8]) )||
( (currGameGrid[6]==currGameGrid[4])&&(currGameGrid[4]==currGameGrid[2]) ) ){
console.log('Player 1 wins!')
预期是否要运行代码块,但不会运行。将不胜感激任何帮助或建议!提前谢谢