我希望有人可以提供幫助。我已經看過堆棧中的JavaScript示例,但可以使用下面的語句來工作。當添加OR語句時發生錯誤。有人可以幫助語法?與我們的代碼Javascript IF和OR語句
if ((this.drawX >= CANVAS_WIDTH - this.width && this.isRightKey==true)
|| (this.drawX <= 0 - this.width && this.isLeft Key==true))
{
this.speed = 0;
}
else {
this.speed =5;
}
問題:
if (this.drawX >= CANVAS_WIDTH - this.width && this.isRightKey)
|| ((this.drawX <= -this.width && this.isLeftKey) {
this.speed = 0;
} else {
this.speed = 5;
}
看來你的條件語法是錯誤的。試試這個:if((this.drawX> = CANVAS_WIDTH - this.width && this.isRightKey == true) ||(this.drawX <= 0 - this.width && this.isLeft Key == true)) ' – dlopez
你好像在'isLeft'和'Key'之間有一個空格,這是錯誤的。你不必檢查一個布爾值== true。根據定義,這只是真的或假的。 – ManoDestra