I'm facing a challenge with this beginner problem.
"A task for you: Calculate the average score of a class whose test scores have been graded by a teacher.
Your mission is to complete the getAverage function, which receives an array of test scores and calculates the average score.
The average score is determined by adding up all the individual scores and dividing by the total number of scores.
average = sum of all scores / total number of scores I've provided a couple of function calls so that you can test your code as well.
Pointers:
You can utilize a loop to iterate over the scores array and sum up all the scores. Utilize the length property to find out the total number of scores."
This is the code snippet that I crafted:
function getAverage(scores) {
let sum = 0;
for (let i = 0; i < scores.length; i++) { sum += scores[i]; }
}
console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]));
console.log(getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95]));
I'm encountering issues with it. Can you help me understand why?
I expected this function to iterate through the getAverage array, sum up the values, and present the average result.