Why its not getting correct value for non-alphabetic characters?

Tell us what’s happening:

Your code so far


function rot13(str) 
{
let l=str.length;
let ans="";
for(let i=0;i<l;i++)
{
  if(65<=str[i].charCodeAt()<=90)
  {
    let x=((str[i].charCodeAt()-65+13)%26)+65;
    ans+=String.fromCharCode(x);
  }
  else
  {
    ans+=str[i];
  }
}
return ans;
}

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/81.0.4044.113 Safari/537.36.

Challenge: Caesars Cipher

Link to the challenge:

Your if condition is true for more cases than you expect. You can paste this at the end of your code and see whether console output is as it should be.

let b = 100;
console.log(65 <= b <= 90);