2016-04-28 45 views
-1

我在使用CodeAcademy的代碼時遇到問題。我將它與其他通過本節的人員進行了比較,我找不到這個錯誤。Codeacademy:循環和數組2(javascript)

我不斷收到 「語法錯誤:參數列表後缺少)」

var names = ["Andy", "Paige", "Damian", "Aaron", "Carrie"]; 
for (var i = 0; i < names.length; i ++) 
{ 
    console.log("I know someone called " names[i]) 
} 

//沒有任何人有任何想法,爲什麼?

+1

日誌需要是'的console.log(「我知道有人叫」,名字[我])'或'console.log(「我知道有人叫」+ names [i])' –

+0

謝謝,解決了!它總是那麼簡單。 – andywb26

回答

2

您需要添加一個+號來連接字符串和變量。你的console.log更改爲

console.log("I know someone called " + names[i])

+0

非常感謝!總會有一件我想念的東西破壞了整個代碼! – andywb26

+0

@ andywb26不用擔心安迪。使用代碼學院祝你好運。當我開始學習時,它非常有用:)。 – Matt

0

你忘了將字符串連接到可變

console.log("I know someone called "+ names[i]) 
+0

不客氣 –