Hey all, I am having trouble with the Caesars cipher. It should be working and I can’t understand what the problem is. Here is the code:
function rot13(str) {
var ciph=[];
var decoded=[];
var len=str.length;
//make cipher array in character codes
for(var i=0;i<len;i++){
var cc=str.charCodeAt(i);
if(cc<=77 && cc>=65) {
ciph.push(cc+13);}
if(cc>=78 && cc<=90) {
ciph.push(cc-13);}
if(cc>90 || cc<65){
ciph.push(cc);}
}
//join cipher array and return as string
return String.fromCharCode(ciph.join());
}
rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK");
If I first evaluate ciph.join() before the final return statement, and type in the string manually it works fine, but if I try to do it as above it just returns a red dot. Any ideas?