I'm having trouble with Coderbyte's challenge
Using the JavaScript language, have the function LetterChanges(str) take the str parameter being passed and modify it using the following algorithm. Replace every letter in the string with the letter following it in the alphabet (ie. c becomes d, z becomes a). Then capitalize every vowel in this new string (a, e, i, o, u) and finally return this modified string.
Here's my code:
function LetterChanges(str) {
str = str.toLowerCase();
var al = "abcdefghijklmnopqrstuvwxyz";
var vo = "aeiou";
var newStr = "";
for (var i = 0;i < str.length;i++) {
if (al.charAt(al.indexOf(str.charAt(i))) == "z") {
newStr += "A";
}
else if (str.charAt(i) == " "){
newStr += " ";
}
else {
if (al.charAt(al.indexOf(str.charAt(i))+1) == vo.charAt(vo.indexOf(str.charAt(i)))) {
newStr += vo.charAt(vo.indexOf(str.charAt(i))+1).toUpperCase();
}
else {
newStr += al.charAt(al.indexOf(str.charAt(i))+1)
}
}
}
console.log(newStr);
}
LetterChanges("Argument goes here")
This is returning the following into the console:
bshvnfou hpft ifsf
but what I need to be returned is:
bshvnfOU hpft Ifsf
I can't figure out why my .toUpperCase()
isn't working. Any help that you can provide is very much appreciated!