編寫一個循環和搜索單詞文本的數組,它出現了這個語法錯誤我一直在查看代碼,但似乎無法注意到任何錯誤。SyntaxError:通過數組循環的意外標識符
jshint multistr:true
var text = "Usually, solar companies install\
solar panels on roofs but Elon Musk offers an\
entirely different and ingenious approach";
var myName = "Elon";
var hits = [];
for(var i=0; i <= text.length; i++) {
if(text[i] === 'E') {
for(var j = i; j < (myName.length + i); j++) {
hits.push(text[j]);
}
}
}
if (hits.length === [0]) {
\t console.log("Your name wasn't found!");
} else {
\t console.log(hits);
}
什麼是__'hits.length === [0]'__?你的意思是__'hits.length === 0'__? – Rayon
嘗試使用IDE來發現這些語法錯誤。 Jetbrain的Webstorm對JavaScript編程來說相當不錯。 –