I am trying to take the average of 3 grades for three student (stored in an array of arrays), and then run those averages through a function with an else if statement to check whether the average grades are each and A,B or C.
I would prefer not to have to make a separate function with an else if for each students average (so I would know how to scale this to more than 3 inputs), and I am not sure how I can index the averageGrades array in the function so that I can console.log each element (student) of the averageGrades array and have the else if statement evaluate that particular element (student).
I also tried making an averageGrade variable for each student so that the averageGrades array had single values and not a full equation but ran into the same problem.
var studentGrades = [
[80, 90, 94],
[80, 90, 94],
[80, 90, 94]
]
var studentAvgerages = [
(studentGrades[0][0] + studentGrades[0][1] + studentGrades[0][2]) / 3,
(studentGrades[1][0] + studentGrades[1][1] + studentGrades[1][2]) / 3,
(studentGrades[2][0] + studentGrades[2][1] + studentGrades[2][2]) / 3
]
for (var i = 0; i <= studentAvgerages.length; i++) {
function evalGrades(studentAvgerages[i]) {
if (studentAvgerages[i] >= 90) {
return "A"
} else if ((studentAvgerages[i] >= 80) && (studentAvgerages[i] < 90)) {
return "B"
} else if ((studentAvgerages[i] >= 70) && (studentAvgerages[i] < 80)) {
return "C"
} else {
return "Failed"
}
}
}
console.log(evalGrades(studentAvgerages[0]))
console.log(evalGrades(studentAvgerages[1]))
console.log(evalGrades(studentAvgerages[2]))