Tell us what’s happening:
Describe your issue in detail here.
If I print ‘arr’ before it’s return statement, the code works completely fine and all the results match (I gave all possible inputs to cross-check and the result is right every time). Though it doesn’t run like this. Can someone help me out please?
Your code so far
function rot13(str) {
var str1=str.split(" ");
var arr="";
for(let i in str1)
{
for(let j in str1[i])
{
var integer=str1[i].charCodeAt(j);
if(integer>=65 && integer<78) integer+=13;
else if(integer==33||integer==44||integer==46||integer==47) integer=integer;
else integer-=13;
arr=arr+String.fromCharCode(integer);
}
arr=arr+" ";
}
return arr;
}
rot13("SERR PBQR PNZC");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67
Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher
Link to the challenge: