Iterate Through an Array with a For LoopPassed

Tell us what’s happening:
I wrote a code following the instruction. It has not been accepted. I have reviewed others posts, but the only difference I have seen is i instead of total. I understood that I can declare any variable and the same variable I can initialize to run a code.

Your code so far

// Setup
const myArr = [2, 3, 4, 5, 6];

// Only change code below this line

for (let total = 0; total < myArr.length; total++) {
total += myArr.length[total];

Your browser information:

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

Challenge: Iterate Through an Array with a For Loop

Link to the challenge:

You can’t use total as both the index variable and the sum.

1 Like

Well you can, won’t cause a syntax error, but the results won’t be what you want.


(post deleted by author)

My another mistake was that I wanted to add the next number and assign to “total” variable as well as to check the length of the array. This will throw undefined. Thank you both

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.