|
Find the average of all the numbers in your array that are less than the highest score and greater than the average score
<?xml version = "1.0"?> <!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>Program with Arrays Template</title>
<script type = "text/javascript"> <!-- var a = new Array( 100 ); // create an Array var count = 0; var out = ""; function buttonPressed() { var searchKey = searchForm.inputVal.value;
if ( searchKey == "" ) findAverage(); else { a[count] = parseInt(searchKey); count++; searchForm.inputVal.value = ""; searchForm.inputVal.focus(); } } function findAverage( ) { var high = 0; var avg = 0; var sum = 0;
for ( var x=0; x<count; x++) { if (a[x]>high) high = a[x]; sum = sum + a[x]; } avg = sum/count;
var sum2=0; var c2=0;
for ( var x = 0; x<count; x++) { if (a[x] > avg) if (a[x] < high) { sum2 = sum2 + a[x]; c2++ } }
searchForm.result.value = avg + ", " + high + ", " + sum2/c2; for ( var x=0; x<count; x++) out = out + a[x] + ", ";
searchForm.arrayout.value = out; } // --> </script>
</head>
<body>
<form name = "searchForm" action = ""> <p>Enter integer score or nothing to exit<br /> <input name = "inputVal" type = "text" /> <input name = "search" type = "button" value = "Add" onclick = "buttonPressed()" /><br /></p>
<p>Result<br /> <input name = "result" type = "text" size = "30" /></p>
<p>Array Dump<br /> <input name = "arrayout" type = "text" size = "80" /></p> </form> </body> </html>
Find the highest even number in your array that is less than the average
<?xml version = "1.0"?> <!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>Program with Arrays Template</title>
<script type = "text/javascript"> <!-- var a = new Array( 100 ); // create an Array var count = 0; var out = ""; function buttonPressed() { var searchKey = searchForm.inputVal.value;
if ( searchKey == "" ) findAverage(); else { a[count] = parseInt(searchKey); count++; searchForm.inputVal.value = ""; searchForm.inputVal.focus(); } } function findAverage( ) { var avg = 0; var sum = 0;
for ( var x=0; x<count; x++) { sum = sum + a[x]; } avg = sum/count;
var high = 0;
for ( var x = 0; x<count; x++) { if (a[x] % 2 == 0 ) if (a[x] < avg) if (a[x] > high) high = a[x]; }
searchForm.result.value = high; for ( var x=0; x<count; x++) out = out + a[x] + ", ";
searchForm.arrayout.value = out; } // --> </script>
</head>
<body>
<form name = "searchForm" action = ""> <p>Enter integer score or nothing to exit<br /> <input name = "inputVal" type = "text" /> <input name = "search" type = "button" value = "Add" onclick = "buttonPressed()" /><br /></p>
<p>Result<br /> <input name = "result" type = "text" size = "30" /></p>
<p>Array Dump<br /> <input name = "arrayout" type = "text" size = "80" /></p> </form> </body> </html>
Find the average score for all tests that are within 10 points of the average score.
<?xml version = "1.0"?> <!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>Program with Arrays Template</title>
<script type = "text/javascript"> <!-- var a = new Array( 100 ); // create an Array var count = 0; var out = ""; function buttonPressed() { var searchKey = searchForm.inputVal.value;
if ( searchKey == "" ) findAverage(); else { a[count] = parseInt(searchKey); count++; searchForm.inputVal.value = ""; searchForm.inputVal.focus(); } } function findAverage( ) { var avg = 0; var sum = 0;
for ( var x=0; x<count; x++) { sum = sum + a[x]; } avg = sum/count; var sum2=0; var c2=0;
for ( var x = 0; x<count; x++) { if (a[x] < avg + 10) if (a[x] > avg - 10) { sum2 = sum2 + a[x]; c2 = c2 + 1; } }
searchForm.result.value = sum2/c2; for ( var x=0; x<count; x++) out = out + a[x] + ", ";
searchForm.arrayout.value = out; } // --> </script>
</head>
<body>
<form name = "searchForm" action = ""> <p>Enter integer score or nothing to exit<br /> <input name = "inputVal" type = "text" /> <input name = "search" type = "button" value = "Add" onclick = "buttonPressed()" /><br /></p>
<p>Result<br /> <input name = "result" type = "text" size = "30" /></p>
<p>Array Dump<br /> <input name = "arrayout" type = "text" size = "80" /></p> </form> </body> </html>
Find the average of all test scores that fall after the highest score in your array.. That is , if your highest score is the 5th test score, return the average of all test scores from the 6th one to the end of your list.
<?xml version = "1.0"?> <!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>Program with Arrays Template</title>
<script type = "text/javascript"> <!-- var a = new Array( 100 ); // create an Array var count = 0; var out = ""; function buttonPressed() { var searchKey = searchForm.inputVal.value;
if ( searchKey == "" ) findAverage(); else { a[count] = parseInt(searchKey); count++; searchForm.inputVal.value = ""; searchForm.inputVal.focus(); } } function findAverage( ) { var high=0; var highpos = 0;
for ( var x=0; x<count; x++) { if (a[x] > high) { high = a[x]; highpos = x; } } var sum = 0; var c=0; for ( var x = highpos + 1; x<count; x++) { sum = sum + a[x]; c++; }
searchForm.result.value = sum/c; for ( var x=0; x<count; x++) out = out + a[x] + ", ";
searchForm.arrayout.value = out; } // --> </script>
</head>
<body>
<form name = "searchForm" action = ""> <p>Enter integer score or nothing to exit<br /> <input name = "inputVal" type = "text" /> <input name = "search" type = "button" value = "Add" onclick = "buttonPressed()" /><br /></p>
<p>Result<br /> <input name = "result" type = "text" size = "30" /></p>
<p>Array Dump<br /> <input name = "arrayout" type = "text" size = "80" /></p> </form> </body> </html>
|