Caesers Cipher - Challenge Help [Solved]

Hi there. Can someone help me with what’s wrong with the below? I feel like I’m almost there. E.g. for the below I’m getting

F8EE L5<E?

Not sure what i’m doing wrong, why are some characters right but others are wrong?

function rot13(str) { // LBH QVQ VG!
  var res = 0;
  var arr = [];
  var newstr = [];

  for (var i=0; i<str.length; i++) {
    if (str[i].match(/[a-z]/i)) {
    res = str.charCodeAt(i);
    res -= 13; 
    arr.push(res);
    } else {
      res = str[i];
      arr.push(res);
    }
  }
  
  for (var j=0; j<arr.length; j++) {
    if (str[j].match(/[a-z]/i)) {
      newstr.push(String.fromCharCode(arr[j]));
    } else {
      newstr.push(arr[j]);
    }
  }
  newstr = newstr.join("");
  return newstr;
}

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

Ah, I feel silly now for not realising that. I’ve got it now, thanks! :slight_smile: