2017-04-23 58 views
-5

我無法搞清楚爲什麼我的警報命令不工作。我試圖在其他人的問題中尋找答案,但因爲我是一個完全新手,我無法找到解決方案。我的控制檯給了我這個錯誤:practice.js:26 Uncaught SyntaxError:missing)在參數列表之後。感謝您的任何建議。我在我的JavaScript的第一週,這樣下去容易對我請:)Javascript - string + var alert

var firstName = prompt("What is your first name?"); 
var lastName = prompt("What is your last name?"); 

firstName = firstName.toUpperCase(); 
lastName = lastName.toUpperCase(); 

var fullName = firstName + " " + lastName; 

var fullNameLength = fullName.length; 

alert("The string " + fullName + " is " fullNameLength + " characters long."); 
+0

錯誤究竟在哪裏?我懷疑原因可能在此代碼之上。 – Carcigenicate

+1

你在''fullName +'缺少一個'+'是「fullNameLength」'。請注意,這可能會因印刷錯誤而關閉。 –

回答

0

你缺少一個+標誌的警戒參數:

alert("The string " + fullName + " is " + fullNameLength + " characters long."); 
//         ^here 

你應該寫你的代碼在一些適當的編輯器或IDE(webstorm,vs code,...)。這樣編輯會爲你突出顯示那些簡單的語法錯誤,有時甚至會提出一個解決方案。

+0

Děkuji! :)是的,對於這段代碼,我使用了teamtreehouse工作區,所以它沒有突出顯示這個錯誤。我的錯! :) – TommyVee