title: JS: how to shift each letter in the given string N places down in the alphabet?
body: <p>how to shift each letter in the given string N places down in the alphabet? Punctuation, spaces, and capitalization should remain intact. For example if the string is "ac" and num is 2 the output should be "ce". What's wrong with my code? It converts letter to ASCII and adds given number then converts from ASCII to letter back. The last line replaces space.</p>
  
  <pre><code>function CaesarCipher(str, num) {
  
      str = str.toLowerCase();
      var result = '';
      var charcode = 0;
  
      for (i = 0; i &lt; str.length; i++) {
          charcode = (str[i].charCodeAt()) + num;
          result += (charcode).fromCharCode();
      }
      return result.replace(charcode.fromCharCode(), ' ');
  
  }
  </code></pre>
  
  <p>I'm getting </p>
  
  <pre><code>TypeError: charcode.fromCharCode is not a function
  </code></pre>