My code so far:
function rot13(str) { // LBH QVQ VG!
let collection = [];
let result = "";
for(let i = 0; i <= str.length-1; i++) {
if(str[i].charCodeAt(i) >= 65 && str[i].charCodeAt(i) <= 77) {
result += str[i].fromCharCode(str[i].charCodeAt(i) + 13);
} else if(str[i].charCodeAt(i) >= 66 && str[i].charCodeAt(i) <= 90) {
result += str[i].fromCharCode(str[i].charCodeAt(i) - 13);
}
}
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Output:
TypeError: str[i].fromCharCode is not a function
I don't understand why I keep running into this problem, I've tried loops and using arrays to match characters and tried several iterations of applying charCodeAt() and fromCharCode() and I always run into this problem. Can someone please point me in the right direction, I'm obviously looking at it the wrong way but can't figure out how.
Thanks :)