I recently encountered a coding challenge called Letter Changes on a platform called Coderbyte. The challenge requires us to modify a given string following a specific algorithm.
The task is to create a function called LetterChanges(str) that takes a string as a parameter and implements the following algorithm:
Replace each letter in the string with the next letter in the alphabet (for example, a becomes b, z becomes a).
After replacing the letters, capitalize all the vowels (a, e, i, o, u) in the modified string and return the final result.
However, I'm facing an issue with a portion of my code that is responsible for changing the letters to the next alphabet. Here is the snippet of the code:
function LetterChanges(str){
for(var i in str){
if(str.charAt(i).match(/[a-y]/i))
str = str.replace(str.charAt(i),String.fromCharCode(str.charCodeAt(i) + 1));
else if(str.charAt(i).match(/z/i))
str = str.replace(str.charAt(i),"a");
}
// the code to capitalize vowels follows
return str;
}
LetterChanges("Argument goes here") //outputs "Btivpfnu hofs hfsf" instead of "Bshvnfou hpft ifsf"