我正在練習一些代碼,並得到一些錯誤,任何人都可以幫助我。SyntaxError:期望的表達式,得到關鍵字'else'
顯示錯誤,如:
SyntaxError: expected expression, got keyword 'else'
下面是代碼
var ageJohn = 25;
var heightJohn = 165;
var ageSmith = 60;
var heightSmith = 180;
var ageMalli = 24;
var heightMalli = 170;
var scoreJohn = heightJohn + 5 * ageJohn;
var scoreSmith = heightSmith + 5 * ageSmith;
var scoreMalli = heightMalli + 5 * ageMalli;
if (scoreJohn > scoreSmith && scoreJohn > scoreMalli); {
console.log('John wins with ' + scoreJohn);
} else if (scoreSmith > scoreJohn && scoreSmith > scoreMalli); {
console.log('Smith wins with! ' + scoreSmith);
} else(scoreMalli > scoreJohn && scoreMalli > scoreSmith); {
console('Mary wins with ' + scoreMalli);
}
你可以看到的錯誤只是你有的錯誤之一。 在你的else if語句中,括號之前的末尾不應該有分號。 這裏是關於爲什麼不整篇文章: [您的指導分號] [1] [1]:https://www.codecademy.com/blog/78 其他(scoreMalli> scoreJohn && scoreMalli > scoreSmith){ console('Mary with with + scoreMalli);} 您的'else'語句在括號內不能包含任何內容。 如果你想檢查'(scoreMalli> scoreJohn && scoreMalli> scoreSmith),你應該將它重構爲'else if'。 –