14.
What will be the output of the following code?
function calculateAverageScore(scores) {
const total = scores.reduce((sum, score) => sum + score, 0);
return total / scores.length;
}
console.log(calculateAverageScore([76, 82, 90, 88, 94, 87]));
86
89.166
87.16666666666667
86.16666666666667
Correct: D
The function calculateAverageScore takes an array of scores as input. It uses the reduce method to calculate the sum of all the scores and then divides that sum by the number of scores to get the average. In this case, the array [76, 82, 90, 88, 94, 87] has a total sum of 517 and contains 6 scores. So, the average score will be 517 / 6 = 84.5.