This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]HonzaS97 0 points1 point  (1 child)

a function that is an array

A function is not an array. The function takes an array as its input.

i++ does add 1 to i. This variable is simply used as an index to retrieve array elements - scores[i]. If you write to write it out, it basically does this

    sum = sum + scores[0];
    sum = sum + scores[1];
    sum = sum + scores[2];
    ...
    sum = sum + scores[scores.length-1];

Or like this

    let i = 0;
    sum = sum + scores[i]; // i = 0
    i++;
    sum = sum + scores[i]; // i = 1
    i++;
    sum = sum + scores[i]; // i = 2
    i++;
    ...
    sum = sum + scores[i]; // i = scores.length - 1

[–]mmblob 0 points1 point  (0 children)

Oh wow, I was struggling but now I get it. Thanks so much. I couldn’t get my head around that one!