Caesars Cipher Help V2

Task link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher

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 :)

2 posts were merged into an existing topic: Caesars Cipher Project Help

Please do not create duplicate topics for the same challenge/project question(s). This duplicate topic has been unlisted.

Thank you.

1 Like