Iterate Through an Array with a For Loop?

Iterate Through an Array with a For Loop?
0

#1

Tell us what’s happening:

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];
var total = 0;
for (var i = 0; i < myArr.length+; i++){
total =+ myArr[i];
}
// Only change code below this line


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.22 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


#2

What’s your question?


#3
  1. You have a “+” after myArr.length in the loop, the editor should be giving you a SyntaxError, remove it.

  2. You are using =+ instead of += in the for loop variable assignment.