TransWikia.com

A package that I am using is not working in Javascript/HTML

Stack Overflow Asked by york910 on January 11, 2021

I basically got this package where it is suppose to calculate the standard deviation for me. However, when used it does not work. I am new to javascript so anything will help. Thankyou!

function standardDeviation(values) {
  var avg = average(values);

  var squareDiffs = values.map(function(value) {
    var diff = value - avg;
    var sqrDiff = diff * diff;
    return sqrDiff;
  });

  var avgSquareDiff = average(squareDiffs);

  var stdDev = Math.sqrt(avgSquareDiff);
  return stdDev;
}

function average(data) {
  var sum = data.reduce(function(sum, value) {
    return sum + value;
  }, 0);

  var avg = sum / data.length;
  return avg;
}

function myfunction() {
  var stdDev = standardDeviation([1, 2, 3, 4, 5, 6, 7, 8, 9, 25]);
  document.getElementById("demo").innerHTML = stdDev;
}
<p id="demo"></p>

<button <button onclick="myFunction()">Try Me</button>

One Answer

Guy pointed out I am terrible at spelling and that I make obvious typos. Should be myfunction() to match with myfunction()

Answered by york910 on January 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP