Tell us what’s happening:
Hello, I am really struggling to understand how to tackle this. I am wondering where in the previous lesson we learnt how to do this? It feels like this has not been taught so far and we are suddenly expected to create a function to find averages of two arrays, with no info on how to do this? I initially tried by defining the arrays of scores as score and score2 at the top. But having read other posts on the forum this seems incorrect. I also have no idea why there are two console logs at the bottom with all the scores.
Your code so far
// User Editable Region
/*let score = [92, 88, 12, 77, 57, 100, 67, 38, 97, 89];
let score2 = [45, 87, 98, 100, 86, 94, 67, 88, 94, 95];
let total = "[92 + 88 + 12 + 77 + 57 + 100 + 67 + 38 + 97 + 89 + 45 + 87 + 98 + 100 + 86 + 94 + 67 + 88 + 94 + 95]";*/
function getAverage(score) {
let sum = 0;
for (let i = 0; i <= score.length; i++){
sum+= score[i];
}
return sum / score.length;
}
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]));
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 1