Caesars Cipher - so close but not all numbers converting to proper characters?

Tell us what’s happening:
i seem to be getting close but any hints would be appreciated as to why i am getting the right output but missing only a few letters in the translation i am lost as to where i went wrong and rather get some advise before looking at answers as this is the first day ive been able to start completing code challenges independently and it feels damn good thanks for your time and help
lucas

Your code so far

function rot13(str) { // LBH QVQ VG!
  var encoded = [];
  var i = 0;
  var letters = str.split("");
  while (i < letters.length) {
     Encoded = letters[i].charCodeAt();
     less = Encoded - 13;
     encoded.push(less);
     i++;
  }
  var j = 0;
  while (j < encoded.length) {
      encoded = String.fromCharCode.apply(null, encoded);
      j++;
      return encoded;
  }
//     return encoded;
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/caesars-cipher

Thank you so much for your fast response I’ll see what I can make happen in light of your advice much appreciated !! :slight_smile:

So I did it! :smiley:

function rot13(str) { // LBH QVQ VG!
  var encoded = [];
  var i = 0;
  var letters = str.split("");
  
  while (i < letters.length) {
     Encoded = letters[i].charCodeAt(); 
     less = Encoded - 13;
     more = Encoded + 13;
   
    if (Encoded >= 78){
       encoded.push(less);  
    } else if (Encoded < 78 && Encoded > 64) {
      encoded.push(more);
    } else if (Encoded < 64) {
      encoded.push(Encoded);
    }
     i++;
  }
// return encoded;  
  var j = 0;
  while (j < encoded.length) {
      encoded = String.fromCharCode.apply(null, encoded);
      j++;
      return encoded;
}
    return encoded;
}

// Change the inputs below to test
rot13("SERR CVMMN!");