Tell us what’s happening:
I’m not getting the desired output.
Instead of getting output as FREE CODE CAMP, this is what I’m getting:
FREE-CODE-C[MP. My code is given below. Help is appreciated.
Your code so far
function rot13(str) { // LBH QVQ VG!
arr1 = [];
for(var i=0;i<str.length;i++){
if(str.charCodeAt(i)>=65 || str.charCodeAt(i)<=90){
if(str.charCodeAt(i)<=78){
arr1[i] = String.fromCharCode(str.charCodeAt(i)+13);
}
else{
arr1[i] = String.fromCharCode(str.charCodeAt(i)-13);
}
}else{
arr1[i] = str.charCodeAt(i);
}
}
return arr1.join("");
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/caesars-cipher