- 1). Launch the standard, plain-text editor application that is available on your computer.
- 2). Enter the following code into the text editor:
<html>
<body>
<h1>Calculate Standard deviation</h1>
<script type="application/javascript" >
var stats=new Array()
function calcstats(a,b,c,d,e,f) {
var sumdev=0;
var standardev=0;
var results=new Array()
// averaging the numbers
var mean=(a+b+c+d+e+f)/6;
// subtracting the each number from the mean and squaring the difference
sumdev=sumdev+Math.pow((mean-a),2);
sumdev=sumdev+Math.pow((mean-b),2);
sumdev=sumdev+Math.pow((mean-c),2);
sumdev=sumdev+Math.pow((mean-d),2);
sumdev=sumdev+Math.pow((mean-e),2);
sumdev=sumdev+Math.pow((mean-f),2);
// dividing the result by the degrees of freedom
standardev=Math.sqrt(sumdev/5);
// storing the results in the array
results[0]=mean;
results[1]=standardev;
// returning the array
return results;
}
// function call to get average
// and storing the results in the array, stats
stats = calcstats(1, 5, 4, 6, 10, 18);
document.write ("The average is is " + stats[0]);
document.write ("");
document.write ("The Standard Deviation is +- " + stats[1]);
</script>
</body>
</html> - 3). Click the "File" menu. Select the "Save" option. Save under the file name, "test.html."
- 4). Launch the web browser that is available on your computer. Click on the "File" menu item and select "Open File."
- 5). Locate the file "test.html" just created, select it with the mouse and then click on "Open."
- 6). Your browser should display:
The average is is 7.333333333333333
The Standard Deviation is +- 5.988878581726855
SHARE