我有一個令人沮喪的時間試圖讓這個工作,Chrome繼續顯示未捕獲的語法錯誤,但作爲一個初學者的JavaScript,我不知道在哪裏看。任何幫助或指針,將不勝感激Javascript - Uncaught SyntaxError:意外的標識符
function details(user) {
var fuel = prompt("Would you prefer petrol or diesel?");
var passengers = prompt("How many passengers will there be?");
var aircon = prompt("Do you require air-conditioning?");
var transmission = prompt("Do you want a Manual, Semi-Automatic or Automatic Transmission?");
var hire = prompt("How long would you like to hire a vehicle for? (Day Hire, Weekend Hire or Weekly Hire)");
if (fuel == "petrol" && passengers == "2" && aircon = "yes" && transmission == "semi-automatic") {
result = "Lambourghini Aventador";
} else {
result = "some form of SUV"
}
if result = "Lambourghini Aventador") {
if (hire == "Day hire") {
cost = 2000;
}
if (hire == "Weekend hire") {
cost = 3800;
}
if (hire == "Weekly hire") {
cost = 12000;
}
}
}
通常錯誤信息伴隨着一個行號。你甚至可以點擊它,它會告訴你確切的錯誤在哪裏。 – 2012-04-10 11:14:12
快速瀏覽告訴我你錯過了';'在結果=「某種形式的SUV」之後。不知道這是否是問題。 – 2012-04-10 11:14:56
我還會將if語句更改爲if((fuel ==「petrol」)&&(passengers ==「2」)&&(aircon ==「yes」)&&(transmission ==「semi-automatic」) )'。哦,你在'(aircon =「yes」)中缺少'=',那應該是'(aircon ==「yes」)' – 2012-04-10 11:16:31