I am trying to change the characters of a string using for loop. My aim is to change each character with the following one. For example a should be converted to b, b is to c and finally z to a, etc. I have written the following code but it doesn't work.
function LetterChanges(str) {
var char = "abcdefghijklmnoprstuvyz";
for(var i = 0; i < char.length; i++) {
var newStr = str.replace(/char[i]/gi, char[i + 1]); // the problem is here
}
return newStr;
}
// keep this function call here
console.log(LetterChanges(readline()));