Hello,

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.

I created an external javascript file and embedded inside the strict XHTML file
here is what I got :-

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Calculator</title>
<script type="text/javascript" src="mean.js"></script>
</head>

<body>
<p>This page calculates mean and standard deviation</p>
</body>
<script type="text/javascript">
var n=new Array();
</script>
</html>

I decide to write MeanCalculation function and standardDevationCalculation function and NUmberReader function

My NumberReader function is

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]);
  }
}

Is this function correct?
I need help in writing mean function

function meanCalculation()
         {
               var i;
               var sum;
              var mean;
             for(int i = 0; i<this.n.length;i++)
             {

thanks,

Hello,

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.

I created an external javascript file and embedded inside the strict XHTML file
here is what I got :-

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Calculator</title>
<script type="text/javascript" src="mean.js"></script>
</head>

<body>
<p>This page calculates mean and standard deviation</p>
</body>
<script type="text/javascript">
var n=new Array();
</script>
</html>

I decide to write MeanCalculation function and standardDevationCalculation function and NUmberReader function

My NumberReader function is

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]);
  }
}

Is this function correct?
I need help in writing mean function

function meanCalculation()
         {
               var i;
               var sum;
              var mean;
             for(int i = 0; i<this.n.length;i++)
             {

thanks,

First thing, please remove keyword this. There is no need to use this.n ....
Rest is fine and I hope you will be able to solve it yourself. Still if you could not develop the function ... please provide the formulae for the mean and standard deviation.

Regards

dude, javascript requires "this" to access instance variable. Please if you are not sure about anything dont try to help other people. You will just mess up their thinking. thanks,

Hope that this will help you up...

<html>
<head> 
<title>Calculator</title>

<script type="text/javascript">
 function numberReader()
{ x = [];
  n = prompt('Enter a number that is separated by "space" or ","','');
 m = n.replace(/(\s)|(\,)/g, '').slice();
for ( var i = 0; i < m.length; i++) { 
  x[i] = m[i]; }
 document.write((x[0]*1 + x[3]*1));
}
</script>
</head>
<body>
<br />
<br />
<p> This demo will convert UI value into an array and add it on the base reference.
(eg. Assuming that the array  x[0] has a value of 1 and x[3] has a value of 4, then the output result wil be 5. It will return NaN value if the ref is out of range! Hope it clears you up. Note that it should be separated by "space" or "," Enjoy...</p>
<p> <script type="text/javascript">

numberReader();
</script> </p>
</body>
</html>
This article has been dead for over six months. Start a new discussion instead.