I would like to change if/else statement to loops in a function that receives a string and return to a new string which is changed the vowel letters to the next letter after it.
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'))
how to change if/else statement below to loops ?
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]}
or i don't mind you change it besides loop, or make it shorter
if/elseto aloop- the two things are two different programming constructsreturn str.split('').map(l => 'aeiou'.includes(l.toLowerCase()) ? String.fromCharCode(l.charCodeAt(0) + 1): l).join('');