How to make this code to work?
Please give me some advices so to work this properly!
for(var i = 0;i<str.length; i++){
g = str.charCodeAt(i);
if(g < 65 || g > 90){
x += String.fromCharCode(g);
}
if(g < 78){
if(g > 90){
x += String.fromCharCode((g - 90) + 64);
}
x += String.fromCharCode( g + 13);
}else{
x += String.fromCharCode( g - 13);
}
}
return x.replace(/-|!|\.|\?/gi,'');
}
// Change the inputs below to test
rot13("LBH QVQ VG!");
Ok i made this solution. But even that i can’t pass the task. Why is that, where im wrong?
function rot13(str) { // LBH QVQ VG!
var g = ' ';
var h = ' ';
var map = Array.prototype.map;
var a = map.call(str, function(x) {
return x.charCodeAt(0);
});
for (var i in a){
if(a[i] >= 78 && a[i]<= 90){
g+= a[i] - 13 + ' ';
}
else if(a[i]<= 78 && a[i] >= 65){
g+= a[i] + 13 + ' ';
}
else{
g+= a[i] + ' ';
}
}
var y = g.split(' ').slice(1, -1);
for(var q in y){
h+= String.fromCharCode(parseInt(y[q]));
}
return h;
}
// Change the inputs below to test
rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.");`Preformatted text`
Yes i figured that out when i checked again string’s length. i solve it and pass the task. Thanks for the answer. 