Assignment 4
by Ryan Brown
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
Human Memory Model<br/><br>
<p>
Students Participating in a psychology experiment attendended several lectures on a subject and took an exam. Every month for a year after the exam, the students took a retest to see how much of the material they remembered. The average scores for the group are given by the following human memory model
</p>
<br>
f(t)=Original score-6ln(t+1), 0 ≤ t ≤ 12
<br>
Where t is the time in months.
<br>
<br>
<form name="inputForm" method="post">
Input Original Score: <input type="number" id="ogscore" size="5" value="75" min="1" max="100"/><br/>
Input Time(in months): <input type="text" id="time" size="5" value="2" /><br/>
<br/><br/>
<input type="button" value="Calculate" id="calculate"/>
<input type="button" value="Plot" id="plot" />
<br/><br/>
<B><p id="answer"> </p></B>
<br>
<p id="output"> </p>
<br>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</form>
<div id="container" style="min-width: 400px; height: 500px; margin: 0 auto"></div>
JavaScript
// Global variables
var ogscore = 0;
var time = 0;
var timec = 0;
var sum = 0;
var n = 0;
var x = new Array();
var y = new Array();
var v = new Array();
function calculateY(ogscore, time, timec, xt)
{
var totaltime = Number(xt) + 1;
var lntotal = Number(Math.log(totaltime));
var simplify = Number((6 * lntotal));
var sum = Number((ogscore - simplify).toFixed(2));
return sum;
return
}
function calculate() {
ogscore = Number($('#ogscore').val());
time = Number($('#time').val());
timec = Number('1');
var xmin = 0;
var xmax = 12;
var xt = Number('0') ;
var i = 0;
for (xt = xmin; xt <= xmax; xt++) {
x[i] = xt;
y[i] = calculateY(ogscore, time, timec, xt);
v[i] = [x[i], y[i]];
i++;
}
n = i - 1;
}
function displayValues()
{
var s = "";
for (var i = 0; i <= n; i++)
{
s += "After " + x[i] + " months, the average test score is: " + y[i] + "<br/>";
}
output.innerHTML = s;
}
function plotValues()
{
calculate();
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Human Memory Model',
x: -20 //center
},
xAxis: {
title: {
text: 'Time'
}
},
yAxis: {
title: {
text: 'Test Score'
}
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
...