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

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){
          final += String.fromCharCode(res);
        else if (res>=78 && res<=90){
        final += String.fromCharCode(res);}  
      return final;     
    // Change the inputs below to test
    rot13("LBH QVQ ?VG");

I finally got it working by adding this:

  else {
          final += strUpper[i];

so happy to complete this challenge. Thanks to freecodecamp.

1 Like

It was definitely my facourite challenge so far!

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?

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.