Trouble with Caesars Cipher specifically the fromCharCode() function

    function rot13(str) { // LBH QVQ VG!
  for(var i=0;i<str.length;i++){
    if(str.charAt(i).match(/[A-Z]/))
    {
      var letter=str.fromCharCode(str.charCodeAt(i)+13);
      str.replace(str.charAt(i),letter);
    }
  }
  return str;
}`Preformatted text`


`indent preformatted text by 4 spaces`

Hey guys I keep getting a type error saying fromCharCode() is not a function.
I don’t understand why.
I know that str.charCodeAt(i) returns the unicode value for a character in a string and the argument that fromCharCode() uses numbers and returns the characters corresponding to that value.

You get .fromCharCode() directly from the String object, not from any string value.

var letter = String.fromCharCode(...);
1 Like

wow I feel foolish now. Thank you.

This https://github.com/Deityhub/Caesars-Cipher/blob/master/Cipher.js will help in solving your issue