Hi all, I'm going through this book called "Head First HTML5 Programming" and it is teaching a lot of javascript in the first few chapters in order to understand the javascript APIs you can use with HTML5. The book doesn't seem to have it's own forum so thought I'd just post my question here if that's ok. Here's the code I'm having a hard time understanding:

Code:
function addUp(numArray) {
     var total = 0;
     for (var i = 0; i < numArray.length; i++) {
          total += numArray[i];
     }
     return total;
}

var theTotal = addUp([1, 5, 3, 9]);
So then the question in the exercise is what is the value of theTotal? I couldn't figure out what it was so I looked up the answer and found it to be 18. So I see that the numArray was added up right? 1 + 5 + 3 + 9 = 18
But I'd like to understand why? I understand up to the point of the line that says:

Code:
total += numArray[i];
That's what's throwing me off. So if I understand right...the for loop will loop as long as it's less than 4 because numArray.length is the amount of the items in the array which is 4 right incrementing by 1 each time from 0 up? But I don't understand that total line.