Caesar's Cypher - Anybody knows what is wrong with my code?

function rot13(str) { // LBH QVQ VG!
  for(var a=0;a<str.length;a++){
    if(str.charCodeAt(a)>=65 && str.charCodeAt(a)<=78){
    str.replace(str.charCodeAt(a),str.CharCodeAt(a+13));
    }
    else if(str.charCodeAt(a)>78 && str.charCodeAt(a)<=91){
    str.replace(str.charCodeAt(a),str.charCodeAt(65+91-str.charCodeAt(a)));
    }
      else{
        
      }
  return str.fromCharCode(a);
  }
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

I didn’t read it all but I noticed this:

str.replace(str.charCodeAt(a),str.CharCodeAt(a+13));

Don’t use replace for this, instead what I suggest is that you somehow target alpha characters (letter) and cipher them accordingly. Remember that strings are immutable so you have some choices like splitting the string into characters (str.split(""), to join again charList.join("")) and modifying only letters; or you could use Regular Expressions to target letters and cipher them accordingly.

I don’t understand why it allways says its not a function, any clue to the type of error? In the console outside of fcc it gives me the same error.