I have a small javascript app that lets the user enter in a name and a mark, then store it in a cookie. This works fine. I need it to now take the numbers from the cookie and calculate the mean and standard deviation.

Code is this

<html>
<head>
<title>Grader 101</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body,td,th {
	font-family: Calibri, Tahoma, Arial Narrow;
	font-size: 12pt;
}
-->
</style>
<script type="text/javascript">
var num = 0;
var lastEntry;
lastEntry = num;
function WriteCookie()
{
	var allowed=/^[a-zA-Z]+$/;

	if(document.gradeAdd.studentName.value.match(allowed))
	{
	num = num+1;	
	student=escape(document.gradeAdd.studentName.value)+";";
	score=escape(document.gradeAdd.studentGrade.value)+";";
	document.cookie="Student" + num + "=" + student;
	document.cookie="Score" + num + "=" + score;
	}
	else
	{
		alert("Enter a valid name");
		return;
	}
}

function ReadCookie()
{

   var allcookies = document.cookie;
   alert("All Cookies : " + allcookies );

   cookiearray  = allcookies.split(';');

   for(var i=0; i<cookiearray.length; i++)
   {
      name = cookiearray[i].split('=')[0];
      value = cookiearray[i].split('=')[1];
   }
}

function ShowMean()
{
		
}
</script>

</head>
<body class="oneColFixCtrHdr">

<div id="container">
  <div id="header">
    <h1>Grader 101  </h1>
  </div>
  <div id="mainContent">
    <form name="gradeAdd" method="post" onSubmit="return false;">
      <p>Please enter the student name and the number of marks achieved</p>
      <table width="1211" border="0">
        <tr>
          <td width="113">Student Name:</td>
          <td width="120"><input type="text" name="studentName" size="20"></td>
          <td width="15">&nbsp;</td>
          <td width="124">Student Grade:</td>
          <td width="120"><input type="text" name="studentGrade" size="20"></td>
          <td width="86"><label>
            <input type="submit" name="addItem" id="button" value="Add Details" onClick="WriteCookie()">
          </label></td>
          <td width="105"><label>
            <input type="submit" name="clearRecords" id="button2" value="Clear Records">
          </label></td>
          <td width="494">
          </td>
        </tr>
      </table>
    </form>
    <hr>
    <p>Below are your options to: View the Marks, Show the Mean, Show the Standard Deviation, Show a Graph</p>
    <table width="550" border="0">
      <tr>
        <td><input type="button" name="showMarks" value="Show the Marks" onClick="ReadCookie()"></td>
        <td></td>
        <td><input type="button" name="showMean" value="Show the Mean"></td>
        <td>&nbsp;</td>
        <td><input type="button" name="showStdDev" value="Show the Standard Deviation"></td>
        <td>&nbsp;</td>
        <td><input type="button" name="showGraph" value="Show a Graph"></td>
      </tr>
    </table>
    <hr>
    <p>&nbsp;</p>
</div>
</div>
</body>
</html>

The cookies are paired/set out like this

Name1: Jack; Score1: 23; Name2: Mat; Score2: 79;

each name and score with the same number are a belonging to the same entry

I need to take the number from the Cookies and work out the mean and standard deviation

How can i do this?

The numbers you want are in the odd elements of cookiearray.
If that's not the problem, are you expecting someone to do the math for you?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.