Iterate Through an Array with a For

Tell us what’s happening:
i’m not understand that’s problem because the explications are not very clear give the good code please

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 total = 0; total == myArr.length; total++) {
  myTotal = myArr[total];
}

Your browser information:

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

Link to the challenge:

The second part of a for statement is the condition. The loop will continue repeating only while the condition is true. Because total is 0 and 0 is not equal to myArr.length, the condition is never true and your loop does not execute.

1 Like

Yes. My problem was because there is a trap. It was write as “myTotal” and “i”. So it was really “total” only wich we must employed.
A trap wich was put my head over the engine lathes. Thank you very much!