Caesars Cipher broken

Tell us what’s happening:
Hi all!

This is my first post here so cut me some slack if my code sucks.
For some reason, the code works well when I run it on visual studio, I pass all the tests. When I run the code on the website, it says it sucks:(

Why does my code not work on the website?!!?!

Your code so far

var ans='';

var d='';
var charFromString="";
var charFromStringCode="";
var ModcharFromStringCode="";
var ModcharFromString_String="";



function rot13(str) {
    // get char values from input
    var len = str.length;

    
    for (i = 0; len-1>= i; i++) {
        
        charFromString = str[i];

        charFromStringCode = str[i].charCodeAt(0);
        
        
        if( charFromStringCode>77 && charFromStringCode<=90 ) {
            ModcharFromStringCode=charFromStringCode-13;
        }
        else if( (65 <= charFromStringCode) && (charFromStringCode<=77) ) {
            ModcharFromStringCode = charFromStringCode+13;
        }
        else {ModcharFromStringCode=charFromStringCode;}
        
        ModcharFromString_String= String.fromCharCode(ModcharFromStringCode);
        
        ans+=ModcharFromString_String;
    }
    return ans;


}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36.

Challenge: Caesars Cipher

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums


Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.

Example:

var myGlobal = [1];
function returnGlobal(arg) {
  myGlobal.push(arg);
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  myLocal.push(arg);
  return myLocal;
} // reliable - always returns an array of length 2