Exercises:
20 judges scored for a contestant, removed 1 highest points, removed 1 minimum points, and averaged
Ideas:
1. html
2. Add Event: Click on the next one when the jury + + text box empty The value of the text box to JS
var btn = document.getElementById ("btn");
Btn.setattribute ("Oncilk", "Next ()"); Define an array
var arr = [],
n=0;
function Next () {//Get score text box get score
var Fs=document.getelementbyid ("Fenshu");
Arr[n]=fs.value;
n=n+1; The number of judges has changed. Find the value of element modified element
document.getElementById ("SP1"). Innerhtml=n=n+1;
Fs.value= ""; Empty Fractional text box
if (n>2) {//Cycle comparison results in highest score lowest score
Getmaxmin ()
}
}
Funcution Getmaxmin () {
var max=arr[0],//Initialize max number minimum
Min=arr[0],
sum=0;
for (var n in arr) {
if (Max<arr[n]) {
Max=arr[n];
}
sum=+sum++arr[n[; Score
}
document.getElementById ("Max"). Innerhtml=max; Place a value in the label to find the element to modify
Document,getelementbyid ("Min"). Innerhtml=min;
Document.getelementbyid.inerhtml= (sum-+max-min)/(arr.length-2);
}
function Show (type) {
var max=arr[0],
Min=arr[0],
Avg=0,
sum=0;
for (var n in arr) {
if (Max<arr[n]) {
Max=arr[n];
}
Sum=+sum++arr[n]; Score
}
avg= (Sum-+max-+main)/(Arr.length-2)
Switch (type) {
Case "Max":
document.getElementById ("Max"). Innerhtml=max;
Break
Case "min":
document.getElementById ("Min"). Innerhtml=min;
Break
Case "AVG";
document.getElementById ("avg"). Innerhtml=avg;
Break
}
Java Review questions