Iterate Through an Array with a For Loop)

Iterate Through an Array with a For Loop)
0.0 0

#1

Tell us what’s happening:
where is the problem I don’t know?

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 myTotal =0;
// Only change code below this line
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/67.0.3396.99 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

you missed a step
the instructions say:
Declare and initialize a variable total to 0

So you need to declare ‘total’ and initialize and then use it in the new for loop


#3

What exactly i would do


#4

so to ‘declare a variable’ use the var keyword. to ‘initialize it’ then set it equal to 0
there is an example of this in the code with the ourTotal variable


#5

Thank you i got it it is very easy and you are very helpfull.