For loop iteration

Tell us what’s happening:

var myArr = [ 2, 3, 4, 5, 6];
var total = 0;
for ( var i = 0; i <  myArr.length;  i++){
    total += myArr[i];
    console.log(total);
}

what should I do if I want to print only final total value i.e. 20 in this case.

Your code so far


// Setup
var myArr = [ 2, 3, 4, 5, 6];
var total = 0;
for ( var i = 0; i < myArr.length; i++){
total += myArr[i];

console.log(total);
}
// Only change code below this line

Your browser information:

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

Challenge: Iterate Through an Array with a For Loop

Link to the challenge:

Hi @croy4744.

You can print it outside the loop.

Thanks buddy!! Thanks a lot.