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:
https://www.freecodecamp.org/challenges/caesars-cipher