Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

So I thought i had this figured out, but then my code was only returning the first test score from each list. After messing around with it I seem to have just confused myself more. Now I am getting NaNs.
Its not the missing semicolons from this screenshot

Your code so far


// User Editable Region

function getAverage(scores) {
  let total = 0;
  
    for (let i = 0; i <= scores.length; i++) {
     total = total + scores[i];
    
  }
  let average = total / scores.length
  return average
}

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/134.0.0.0 Safari/537.36 Edg/134.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

1 Like

You have an OBOE:

At what index in your array will this loop terminate?

2 Likes

Thanks! A mistake i have made plenty of times before. arrays start at 0. Getting back into this after recovering from back problems. I gotta say though, this new pyramid thing is not a good start for new people and tells you want to do rather than tell you what you need to do, if that makes sense. I remember last year when i first started it went over the basics and grew up to projects.

The pyramid seemed like it tried to make that CS50 homework assignment more digestible, which it may, but that shouldnt be the intro for Javascript.

Dunno why I rambled that to you. Thanks again!

3 Likes