"NaN" result when multiplying more than one value in an array by a number
<p>Note: please pay <em>no</em> attention to my beginnings on the "Decrypt" function, button, etc. It has <em>no</em> relevance towards this question.</p>

<p>I've looked practically everywhere for a fix on here and can't seem to find one due to my kinda strange project. I'm a noob at JavaScript so please tell me anything I could improve on. Here's my project: It's basically a Encrypt/Decrypt message thing based on what key you type in.. When you type in the key, and submit it, it gives the key a value based on it's length and ASCII value:</p>

<pre><code>    function submitkey(form) {
  keyinp = (form.key.value)
  var keyl = keyinp.length
  keyasciiout = keyinp.charCodeAt(0)
  document.getElementById("asciikeyout").innerHTML =
  "&lt;b&gt;" + keyinp + "&lt;/b&gt; is your key."

  if (keyl &gt; 4) {
    keyasciitwo = keyinp.charCodeAt(1)
    keyasciithree = keyinp.charCodeAt(2)
    keyasciifour = keyinp.charCodeAt(3)
    keyasciifive = keyinp.charCodeAt(4)
    finalkey = (((keyasciiout + keyasciitwo + keyasciithree + keyasciifour + keyasciifive) / keyl) * 0.5)
  }
  else { alert("Please choose a new key. It must be 5 or more characters.") }

}
</code></pre>

<p>So now you've entered a key and it has a value that plays a role in encrypting/decrypting your messages. Here's the text boxes that you enter in and stuff. </p>

<pre><code>&lt;form name="keyinput"&gt;
  &lt;input type="text" id="key" name="key"&gt;
  &lt;br&gt;
  &lt;input type="button" name="keysub" id="keysub" value="Submit Key" onclick="submitkey(this.form)"&gt;
&lt;/form&gt;
&lt;p id="asciikeyout"&gt;&lt;/p&gt;
&lt;p id="key2"&gt;&lt;/p&gt;
  &lt;br&gt; &lt;br&gt;
  &lt;br&gt; &lt;br&gt;
  &lt;br&gt; &lt;br&gt;

&lt;form name="field"&gt;
  &lt;input type="button" name="decryptbutton" onclick="dec(this.form)" value="Decrypt"&gt;
  &lt;br&gt;
  &lt;textarea id="input" rows="4" cols="50" onkeyup="getascii(this.form)" onkeydown="keycheck(this.form)"&gt;&lt;/textarea&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;textarea id="output" rows="20" cols="70" fontsize="18px" readonly&gt;&lt;/textarea&gt;
&lt;/form&gt;
&lt;p id="res2"&gt;&lt;/p&gt;
</code></pre>

<p>By the way, the keycheck() function is just something where if you type in the textbox and don't have anything entered as a key, it will alert you to create a key.</p>

<p>So whenever you type into the input textbox, it runs getascii(this.form), which, btw, just gets the ASCII values of all of the characters you typed and stores them as a variable, in which this case, is "code":</p>

<pre><code>function getascii(form) {

globalinp=(form.input.value)
var str=(form.input.value);
code = new Array(str.length);
for(var i=0;i&lt;str.length;i++){
code[i]=str.charCodeAt(i);
}

encrypt(code)
  }
</code></pre>

<p>Which, in turn, runs encrypt(), which places the "code" values into an array(i think, this may be the issue. please tell me.):</p>

<pre><code>function encrypt(code) {

 sepcode = code.toString().replace(/,/g, " ")
      asciiarray = sepcode.split(" ");

      arrmult()

  }
</code></pre>

<p>Which, then again, runs a function called arrmult, which is where the trouble begins (i think). </p>

<pre><code>function arrmult() {
 var a = [asciiarray];

var b = a.map((function (x) { return x * finalkey; }).bind(this));

document.getElementById("output").innerHTML =
b
}
</code></pre>

<p>The above code I got from this website. What it does is takes each individual value of the array assigned as the variable A, in this case all of the ASCII values of whatever you typed in the box, and multiplies them by a certain value, which I have set as the value of the key. Note: When I replace the variable A with a string of numbers, like this:</p>

<pre><code>var a = [127,93,28];
</code></pre>

<p>It seems to be working perfectly fine. But, when I use asciiarray instead, it returns back with a value of "NaN", but only when I do more than ONE character. When I only type one character and have the variable a set as this:</p>

<pre><code>var a = [asciiarray];
</code></pre>

<p>It works perfectly fine. But when it updates, and has two or more characters, it results as "NaN" even though the value of asciiarray is the exact same as the numbers above. And when you do reply, please help me realize where to replace what I've done wrong, as I'm a JavaScript complete noob.</p>

<p>If you wish to look at the code completely, here it is. You can even copy and paste it into an HTML file if you wish:</p>

<pre><code>&lt;html&gt;
&lt;body&gt;
  &lt;head&gt;
    &lt;title&gt;Ascii Encryption&lt;/title&gt;
  &lt;/head&gt;

&lt;script&gt;

var code="test"
var sepcode="test"
var keyinp="test"
var keyasciiout="test"
var finalkey="test"
var globalinp="test"
var globalascarr="test"
var multex="test"
var keyasciitwo="test"

function getascii(form) {

globalinp=(form.input.value)
var str=(form.input.value);
code = new Array(str.length);
for(var i=0;i&lt;str.length;i++){
code[i]=str.charCodeAt(i);
}

encrypt(code)
  }
&lt;/script&gt;

&lt;script&gt;

function submitkey(form) {
  keyinp = (form.key.value)
  var keyl = keyinp.length
  keyasciiout = keyinp.charCodeAt(0)
  document.getElementById("asciikeyout").innerHTML =
  "&lt;b&gt;" + keyinp + "&lt;/b&gt; is your key."

  if (keyl &gt; 4) {
    keyasciitwo = keyinp.charCodeAt(1)
    keyasciithree = keyinp.charCodeAt(2)
    keyasciifour = keyinp.charCodeAt(3)
    keyasciifive = keyinp.charCodeAt(4)
    finalkey = (((keyasciiout + keyasciitwo + keyasciithree + keyasciifour + keyasciifive) / keyl) * 0.5)
  }
  else { alert("Please choose a new key. It must be 5 or more characters.") }

}
&lt;/script&gt;

&lt;script&gt;
  function encrypt(code) {

 sepcode = code.toString().replace(/,/g, " ")
      asciiarray = sepcode.split(" ");

      arrmult()

  }
&lt;/script&gt;

&lt;script&gt;
  function arrmult(none) {
 var a = [asciiarray];

var b = a.map((function (x) { return x * finalkey; }).bind(this));

document.getElementById("output").innerHTML =
b
}
&lt;/script&gt;

&lt;script&gt;
  function dec(form) {
    var input = (form.input.value)
    var inputdiv = (input / finalkey)
    var decrypted = String.fromCharCode(inputdiv)
    alert(decrypted)
  }
&lt;/script&gt;

&lt;script&gt;
  function keycheck(form) {
    if (finalkey != null) {
      null
    } else {
      alert("Please enter a key. This will determine how your encryptions and decryptions are made.")
    }
  }
&lt;/script&gt;

&lt;center&gt;

  &lt;br&gt; &lt;br&gt;
  &lt;br&gt; &lt;br&gt;
&lt;form name="keyinput"&gt;
  &lt;input type="text" id="key" name="key"&gt;
  &lt;br&gt;
  &lt;input type="button" name="keysub" id="keysub" value="Submit Key" onclick="submitkey(this.form)"&gt;
&lt;/form&gt;
&lt;p id="asciikeyout"&gt;&lt;/p&gt;
&lt;p id="key2"&gt;&lt;/p&gt;
  &lt;br&gt; &lt;br&gt;
  &lt;br&gt; &lt;br&gt;
  &lt;br&gt; &lt;br&gt;

&lt;form name="field"&gt;
  &lt;input type="button" name="decryptbutton" onclick="dec(this.form)" value="Decrypt"&gt;
  &lt;br&gt;
  &lt;textarea id="input" rows="4" cols="50" onkeyup="getascii(this.form)" onkeydown="keycheck(this.form)"&gt;&lt;/textarea&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;textarea id="output" rows="20" cols="70" fontsize="18px" readonly&gt;&lt;/textarea&gt;
&lt;/form&gt;
&lt;p id="res2"&gt;&lt;/p&gt;

&lt;/center&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>