I ran this code for the section “Iterate Through an Array with a For Loop”, but it keeps saying that total should be declared and initialized to 0, and not to set it to 20. I have done precisely both of those things, but it’s still giving me an error.
// 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];
}
In the future, also post the challenge url or use the Ask for Help button on the challenge? That way, we don’t have to search for the challenge and your code would automatically populate in the post.
I still don’t quite understand what that means; do I replace the 0 with an a? It returns undefined when I do that. I put in myArr, but it still doesn’t return all green. How would you write the line that’s messing the program up?