Hi,
I almost done last challenge ‘Caesars Cipher’ in basic algorithms, but I am stuck on passing non-alphabetic character. My algorithm can decipher, but there is no spaces between words. Any suggestion, tips, what I’m doing wrong?
Here is my code:
function rot13(str) { // LBH QVQ VG!
var decodeStr = "";
for(var i = 0; i < str.length; i++){
var singleChar = str.charCodeAt([i]);
if(singleChar >= 65 && singleChar <= 77){
decodeStr+= String.fromCharCode(singleChar + 13);
}
if (singleChar >= 78 && singleChar <= 90){
decodeStr+= String.fromCharCode(singleChar - 13);
}
}
return decodeStr;
}
// Change the inputs below to test
rot13("SERR YBIR?");
Your code adds a letter to your decodeStr variable if and only if its character code is within those values specified. What should it do otherwise? Where would you put that in your code?