Design and implement a JavaScript program to accomplish the following: 1. Iterat
ID: 3789343 • Letter: D
Question
Design and implement a JavaScript program to accomplish the following:
1. Iterate and accept N test scores and N student names (where 10 <= N <= 20).
2. Compute the sum and average of the scores (display these values).
3. Implement a function that determines the highest score (display this value).
4. Implement a function that determines the lowest score (display this value).
5. Implement a function that determines the letter grade of each score:
90-100 (A); 80 - 89 (b); 70 - 79 (C); 60 - 69 (D); 0 - 59 (F)
6. Display a table showing each student's name, score, and letter grade.
7. The highest and lowest scores should be highlighted with different colors.
Complete the determineGrade function in the sample solution using if statements - not switch statement.
Explanation / Answer
var $ = function (id) {
return document.getElementById(id); // accept an integer for n scores
};
var tests =[id];
var testnames = [id];
var testAvgmarks = 0;
for(var arr=0;arr<id;arr++){
tests[arr];
for(var arr1 = 1; arr1<arr[id]; arr1++){
testnames[arr1];
}
}
for (var i=0; i <tests.length; i++) {
testAvgmarks += tests[i][1];
var avg = (tetsAvgmarks/tests.length);
}
console.log("Average grade: " + (testAvgmarks)/tests.length);
if (avg < 59){
console.log("Grade : F");
}
else if (avg < 70) {
alert("Grade : D");
}
else if (avg < 80)
{
console.log("Grade : C");
} else if (avg < 90) {
console.log("Grade : B");
} else if (avg < 100) {
console.log("Grade : A");
}
var highScore = Math.max.apply(Math, tests);
for (var i in tests) {
if (tests[i] > highScore) highScore = tests[i];
"High Score Student = " + testnames[i] + " " + "High Score = " + highScore;
}
$("results").value = maxScore;
Var minScore = Math.min.apply(Math,tests);
For(var j in tests) {
if (tests[j] < minScore) minScore = tests[j];
"Least Score = " + testnames[j] + " " + "Least Score = " + minScore;
}
$("results").value = minScore;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.