I am supposed to write a program that prompts user to enter the numbers separated by space and when user click “ok” button, it should display the numbers entered with its mean, and standard deviation and the window should ask if user wants to enter numbers again if yes then it should display the new numbers entered, with its mean and standard deviation(old numbers with mean, variance and deviation should be replaced by the new one). the report method should use dynamic HTML so that each new report overlays the old one.
I created an external javascript file and embedded inside the strict XHTML file
I think I got all my functions…Can anyone look into my codes once again!! FOR SOME REASON IT IS NOT WORKING
[code] var n
function ListNumber(num)
{
this.num = n;
}
ListNumber.prototype.numberReader = numberReader();
ListNumber.prototype.meanCalculation = meanCalculation();
ListNumber.prototype.varianceCalculation = varianceCalculation();
ListNumber.prototype.stdDeviation = stdDeviation();
ListNumber.prototype.report = report();
[code]function numberReader()
{
var i;
this.n = prompt(“Enter a list of numbers separated by spaces:”, “”).split(” “);
for(i=0;i<this.n.length;i++)
{
document.write(“<br />[“+i+”] = “+this.n[i]);
}
}
[code]function meanCalculation()
{
var i;
var sum;
var mean;
for(int i = 0; i<this.n.length;i++)
{
sum+=n[i];
}
mean=sum/this.n.length;
}
[code]function varianceCalculation()
{
var variance;
var i;
var sum;
var meanValue;
meanValue = this.meanCalculation();
for(i = 0; i<this.n.length; i++)
{
sum[i]+= (this.n[i]-meanValue)*(this.n[i]-meanValue);
}
return (sum/(this.n.length -1));
}
[code]function stdDeviation()
{
var stdDeviation;
stdDeviation =Math.sqrt(this.varianceCalculation());
}
[code]function report()
{
var choice;
numberReader();
document.getElementById(“Number list”).innerHTML = reportContent;
document.write(“<p> mean:”+ this.meanCalculation()+”.</p>”);
document.write(“<p> variance:”+this.varianceCalculation()+”.<p”>);
document.write(“<p> standard deviation:”+ this.stdDeviation()+”.</p>”);
choice = confirm(“Do you want another calculation”)
if(choice)
{
numberReader();
meanCalculation()
(am I doing right thing?????)
}
Here is my html file :-
[code]
<html>
<head>
<title> random calc</title>
<script type = “text/javascript” src = “math.js”></script>
</head>
<body>
<p>using the prompt enter numbers</p>
<script type = “text/javascript”>
var ab;
var n;
ab = new ListNumber(n);
document.write(“<p>Numbers:”+ab.numberReader()+”</p>”);
document.write(“<p>mean:”+ab.meanCalculation()+”</p>”);
</script>
</body>
</html>
Seems like I have done mistake somewhere, can anyone check my code please please!!
thanks,