所以我正在做一些编程练习,我被困在这一个。这是一个简单的搜索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