Iterate Through an Array with a For Loop help

Tell us what’s happening:

total should be declared and initialized to 0
total is not defined
so what mean?why can’t work?

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 Total = 0;

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) 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

You have defined Total , that is true, however you have not defined total

so change myTotal? or Total = 20?

that still would leave total undefined

I’m finally find it must write lower case can work.:woman_facepalming:
so it is can submit.

1 Like