title: Caesar Cipher in javascript: cipher broken
body: <p>I'm building a Caesar Cipher in javascript. It uses a randomly set variable called <code>currentkey</code> as the cipher's key. it can be a number from -25 to +25, skipping 0.</p>
  
  <p>I can't figure out why the function returns undefined in the beginning of the string, or why it translates the same letter for as long as the string goes, or even why that letter doesn't get translated at all.</p>
  
  <pre><code>var currentkey = 5  //for example
  function convertKey(str) {
      var o_text = str;
      var o_letters = o_text.split("");
      var alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','w','z']
      var c_text, _x = "";
      for (x in o_letters) {
          if (currentkey &gt; 0) {
              _x = alphabet[alphabet.indexOf(x) + currentkey]
          } else {
              _x = alphabet[alphabet.indexOf(x) + (26 - currentkey)]
          }
          c_text = c_text + _x;
      }
      return c_text;
  }
  </code></pre>
  
  <p>For example, running <code>convertKey("example")</code> returns <code>undefinedeeeeeee</code> (undefined + 7 times the first letter in "example").</p>