所以我正在做一些編程練習,我被困在這一個。這是一個簡單的搜索E
的短語。我不明白爲什麼for
無法循環,結果只是確認它沒有在我的短語中找到任何E
。任何人都可以看到我的for
循環有什麼問題嗎?For循環不循環,不能找出爲什麼
/*
* Function that counts E's in a user-enter'd phrase
**/
function countE() {
var phrase = prompt("Which phrase would you lke to examine ?");
if(typeof(phrase) != "string") {
alert("That is not a valid entry!");
return false;
} else {
for(var eCount = 0; eCount < phrase.length; eCount++) {
if(phrase.charAt(eCount) == 'E' || phrase.charAt(eCount) == 'e') {
alert("There are " + eCount + " E's in \"" + phrase + "\".");
return true;
} else {
var report = confirm("I did not find any E's in your phrase. Would you like to try again?");
if(report == true) {
return countE();
} else {
alert("Ok maybe next time!");
return false;
}
}
}
}
}
countE();
eCount狀況在for循環還需要更改爲我 – jing3142
@ jing3142 - 謝謝 –
return CountE()需要返回eCount – jing3142