Caesars Cipher, plz help, what's wrong with my code

Caesars Cipher, plz help, what's wrong with my code
0.0 0

#1

Plz help, wha’ts wrong with my code
My results were same with examples.
Plz help!

Your code so far

var newArr = [];

function rot13(str) { // LBH QVQ VG!
  var newStr = str.replace(/ /g,"_");
  for(var i = 0; i< newStr.length; i++) {
    
    var current = newStr.charCodeAt(i);
    var decode;
    if(current < 78 && current > 64) {
      current = current + 13;
      decode = String.fromCharCode(current);
      newArr.push(decode);
    }
    else if(current > 77 && current < 91) {
      current = current - 13;
      decode = String.fromCharCode(current);
      newArr.push(decode);
    } else {
      current = current;
      decode = String.fromCharCode(current);
      newArr.push(decode);
    }
  }
  console.log(newArr);
  var lastArr = newArr.join('');
  var returnArr = lastArr.replace(/_/g, " ");
  return returnArr;
}

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

Your browser information:

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

Link to the challenge:


#2

newArr is declared outside of the function rot13. Every time you run a test that test solution gets appended to the previous solutions. Just declare newArr inside rot13 function (move to first line inside function).


#3

Thank you so much, it’s run :blush: