38 lines
845 B
HTML
38 lines
845 B
HTML
|
<html>
|
||
|
<head>
|
||
|
<title>Example 8.9</title>
|
||
|
<script type="text/javascript">
|
||
|
var scores = new Array();
|
||
|
var sum = 0;
|
||
|
var count1 = 0;
|
||
|
var count2 = 0;
|
||
|
var count = 0;
|
||
|
var average = 0;
|
||
|
while (scores[count1] != 999)
|
||
|
{
|
||
|
scores[count1]= prompt("Enter the student's grade or enter 999 when you are done: ");
|
||
|
scores[count1] = parseFloat(scores[count1]);
|
||
|
if (scores[count1] == 999)
|
||
|
{
|
||
|
break;
|
||
|
}
|
||
|
sum = sum + scores[count1];
|
||
|
count1 = count1 + 1;
|
||
|
}
|
||
|
average = sum / count1;
|
||
|
for (count = 0; count < count1; count++)
|
||
|
{
|
||
|
if (scores[count] > average)
|
||
|
{
|
||
|
count2 = count2 + 1;
|
||
|
}
|
||
|
}
|
||
|
document.write("The average is: " + average.toFixed(2) + "<br />");
|
||
|
document.write("The number above the average is: " + count2 + "<br />");
|
||
|
document.write("The number below the average is: " + (count1 - count2) + "<br />");
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
</body></html>
|
||
|
|