我想将 if/else 语句更改为在接收字符串并返回一个新字符串的函数中循环,该字符串将元音字母更改为它之后的下一个字母。
function changeVowels(str) {
var alphabet = 'abefijopuvABEFIJOPUV';
var strNew = ""
for(var i = 0; i < str.length; i++){
for(var j = 0; j < alphabet.length; j++){
if(str[i] === alphabet[j] && j%2 === 0){
strNew += alphabet[j+1]
}
}
if(str[i]==='a' || str[i]==='i' || str[i]==='u'||str[i]==='e' || str[i]==='o'){}
else if(str[i]==='A' || str[i]==='I' || str[i]==='U'|| str[i]==='E' || str[i]==='O'){}
else{
strNew+=str[i]
}
}
return strNew
}
console.log(changeVowels('Car'))
如何将下面的 if/else 语句更改为循环?
if(str[i]==='a' || str[i]==='i' || str[i]==='u'||str[i]==='e' || str[i]==='o'){}
else if(str[i]==='A' || str[i]==='I' || str[i]==='U'|| str[i]==='E' || str[i]==='O'){}
else{strNew+=str[i]}
或者我不介意你在循环之外改变它,或者让它更短
猛跑小猪
一只名叫tom的猫
ibeautiful
相关分类