Rot13 code help.... returnStr is undefined?

I can get each line to work separately; but I can’t get the my returnStr to accept the new values: returnStr is undefined?

function rot13(str) { // LBH QVQ VG!
  str = str.split('');
  var rot13 = 13;  
  var returnStr =[];
  for (var i = 0; i < str.length; i++){
    if (str[i].charCodeAt(0) != " "){
       var tempAsciiVal = str[i].charCodeAt(0)-64;
       var offset = tempAsciiVal - rot13;
       var tempChar = "";
       //just replace it.
       if (offset > 0){
        tempChar =  str[i].charCodeAt(0) - rot13;
       } //deal with : gone negative: pack it ontop.
       else {
         tempChar = String.fromCharCode(90 + offset);
     } else{
       returnStr[i] = str[i];
  return returnStr;

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

A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. Thus ‘A’ ↔ ‘N’, ‘B’ ↔ ‘O’ and so on.

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.