title: Standard deviation javascript
body: <p>I am trying to get the standard deviation of a user input string. I have as follows, but it returns the wrong value for SD. The calculation should go as follows:
  Sum values/number values = mean
  Square (sum each  value-mean)
  Sum squares/number values.</p>
  
  <p>Assistance appreciated (and explanation if possible):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function sum() {
    var val = document.getElementById('userInput').value;
    var temp = val.split(" ");
    var total = 0;
    var v;
    var mean = total / temp.length;
    var total1 = 0;
    var v1;
    var temp23;
    var square;
  
    for (var i = 0; i &lt; temp.length; i++) {
      v = parseFloat(temp[i]);
      total += v;
    }
  
    mean = total / temp.length;
  
    for (var i = 0; i &lt; temp.length; i++) {
      v1 = parseFloat(Math.pow(temp[i] - mean), 2);
      total1 += v1;
    }
  
  
    temp23 = total1 / temp.length;
    square = Math.sqrt(temp23);
  
    document.write(total + '&lt;br /&gt;');
    document.write(mean + '&lt;br /&gt;');
    document.write(square);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  
  &lt;head&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;form id="input"&gt;
      &lt;textarea id="userInput" rows=20 cols=20&gt;&lt;/textarea&gt;
      &lt;input id="Run" type=Button value="run" onClick="sum()" /&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>