most efficient way to display this?

shtf2012

New Member
this script takes values into an array, performs some calculations, and displays them. i have that part done, i just want to display the values entered on the left side vertically and in ascending order, and the statistics on the right. i figured a table would do, but i i've always had trouble making html tables from javascript.anyway here's my code:\[code\] <!DOCTYPE html><html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>exercise 4 part 1</title> <script type="text/javascript"> var myArray = []; var arraySize; var clickCounter = 0; function inputSize(){ arraySize = document.getElementById("valueField").value; submitContainer.innerHTML = ""; label.innerHTML = "Enter values to be calculated: "; valueField.valuehttp://stackoverflow.com/questions/15864620/= ""; insertContainer.innerHTML = "<input id='insertButton' value='http://stackoverflow.com/questions/15864620/Insert Values' type='button' onclick='clickCounter++; insert()'> "; } //insert stuff function insert(){ myArray.push(document.getElementById("valueField").value); valueField.valuehttp://stackoverflow.com/questions/15864620/= ""; if (clickCounter == arraySize){ calculate(myArray); } } //calculations function calculate(x){ var sum = 0; var sorted = x.sort(function(a,b){return a-b}) //mean for(var i = 0; i < arraySize; ++i){ sum += parseInt(x); } var mean = sum/arraySize; //variance var variance = 0; for (var i = 0; i < arraySize; ++i){ variance+= (x - mean) * (x-mean); } variance = variance / (arraySize - 1); //standard deviation var sD = 0; sD = Math.sqrt(variance); //display var content = "<table>" + "<thead><th>Values</th><th>Value</th></thead><tbody>"; for (var i = 0; i < arraySize; ++i){ content+= "<tr><td> " + x + "</tr></td><br>"; } content += "</tbody></table>"; output.innerHTML = content; document.write("Number of Values: " + arraySize + " " + "Sorted: " + sorted + " " + "Mean: " + mean + " " + "Variance: " + variance.toFixed(2) + " " + "Standard Deviation: " + sD.toFixed(2)); } </script> </head> <body> <form id="myForm" action="#"> <p> <label id="label">Enter number of values: </label> <input id="valueField" type="number"> <div id="submitContainer"> <input id="submitButton" value="http://stackoverflow.com/questions/15864620/Submit" onclick="inputSize()" type="button"></div> <div id="insertContainer"></div> </p> </form> <div id="output"></div> </body></html>\[/code\]
 
Top