Working on a CoderByte problem and the first for loop isn't executing on the first or last loop. The function is to convert every letter to the next one after it in the alphabet, then switch all vowels to uppercase. For example input "coderbyte" is returning "fpdfsczUE" when it should be "dpdfsczUf". All variables and tests seem to be functioning (see comments). Any help would be appreciated - they give the answers but won't explain why this won't work.
function LetterChanges(str) {
// convert every letter in a string to the letter after in the alphabet,
// then convert all vowels to uppercase, and return the string.
var alpha = "abcdefghijklmnopqrstuvwxyz";
var vowels = "aeiou";
for (var i=0; i<str.length; i++) {
// return (alpha.indexOf(str[i]) !== -1); checks true on first loop
if (alpha.indexOf(str[i]) !== -1) {
//return alpha[alpha.indexOf(str[i]) + 1]; // returns d correctly
// return alpha.indexOf(str[i]) + 1; // returns 3 correctly
//return str[i]; returns "c" correctly
// return str.replace(str[i], "X"); returns Xoderbyte correctly
// return str.replace(str[i+1], alpha[alpha.indexOf(str[i]) + 1]);
//returns cdderbyte correctly
// BUG: why isn't the line below working on the first and last
// loop ?
// ie. input "coderbyte" returns "fpdfsczUE"
str = str.replace(str[i], alpha[alpha.indexOf(str[i]) + 1]);
}
}
//return alpha[alpha.indexOf(str[i])];
for (var j=0; j<str.length; j++) {
if (vowels.indexOf(str[j]) !== -1) {
str = str.replace(str[j], str[j].toUpperCase());
}
}
return str;
}