Ceasars Cipher challenge, can't get the code to work perfectly

Ceasars Cipher challenge, can't get the code to work perfectly
0

#1

This code is working but non-alphabetic characters are removed. Someone help please.

function rot13(str) { // LBH QVQ VG!
var strUpper = str.toUpperCase(); 
var res, i;
var final = "";
for(i=0; i < strUpper.length; i++){
        res = String.charCodeAt(strUpper[i]);
        if (res>=65 && res<=77){
          res+=13;
          final += String.fromCharCode(res);
        }
        else if (res>=78 && res<=90){
          res-=13;
        final += String.fromCharCode(res);}  
      }
      return final;     
    }
    // Change the inputs below to test
    rot13("LBH QVQ ?VG");

#2

I finally got it working by adding this:

  else {
          final += strUpper[i];
        }

so happy to complete this challenge. Thanks to freecodecamp.


#3

It was definitely my facourite challenge so far!


#4

I’ve tried running this code exactly and I get the following error:

Uncaught TypeError: String.charCodeAt is not a function

What am I doing wrong?


#6

I hated this challenge! Granted it was my fault; I was on completely the wrong track, banging my head against a series of brick walls. Thanks for sharing your solution, just skimming through this thread made me realize my mistake and I went back and figured out how to make it work.