Caesars Cipher Code Doesn't work

Caesars Cipher Code Doesn't work
0.0 0

#1

Tell us what’s happening:
Hi guys ; I need your help please. why my code is not working ?
for example for “SERR PBQR PNZC” I must get “FREE CODE CAMP”, instead I am getting"FREE-CODE-CAMP" . I can’t fin my mistake.

Your code so far

function rot13(str) { // LBH QVQ VG!
  var arr = str.split('');
  var originalStr=[];
  for (var i=0 ; i < arr.length ; i++){
    var x = arr[i].charCodeAt(0);
    if((x >= 65)||(x <= 90)){
      if(x < 78){
        originalStr.push(String.fromCharCode(x+13));
      } else{
        originalStr.push(String.fromCharCode(x-13));
      }
    } else {
      originalStr.push(arr[i]);
    }
  }
  return originalStr.join('');
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36.

Link to the challenge:


#2

Your first if statement (seen below) is incorrect, which is causing you to convert non-letters to other characters.

if((x >= 65)||(x <= 90)){

When x is 32 (space character) the above evaluate to true. Do you understand why?


#3

Thank you. I changed it and it is working now.