Iterate Through an Array with a For Loop!

Tell us what’s happening:

I am a bit lost to this one some of these concepts I am just not getting…

Your code so far


// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];
}

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line

var myTotal = 0;

for (var i = 0; i < myArr.length; i++) {
  myTotal += myArr[i];
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop

What exactly are you not getting?

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

I think this might help yo better understand how it works

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line

var total = 0;
for (var i = 0; i < myArr.length; i++){
0 1 2 3 4 5
2 3 4 5 6

total += myArr[i];
total = total + 0 1 2 3 4 5 + [0 1 2 3 4 5]
}