我写了一个关于在单词中查找元音的代码。感谢console.log,我得到了输出,它可以工作。但是一旦我尝试返回,它不会返回任何东西..我不明白为什么?
这里的代码:
function vowelCount(str) {
let word = str.split("");
// console.log(word);
// console.log(word.length - 1);
let count = 0;
for (let i = 0; i <= word.length - 1; i++) {
if (
str[i] === "a" ||
str[i] === "e" ||
str[i] === "i" ||
str[i] === "o" ||
str[i] === "u" ||
str[i] === "y"
) {
count = count + 1;
}
}
// console.log(count);
return count;
}
vowelCount("hello");
vowelCount("thereactor");
跃然一笑
慕斯709654
拉风的咖菲猫
白衣非少年
相关分类