Basic JavaScript - Iterate Through an Array with a For Loop

Tell us what’s happening:
Describe your issue in detail here. I thought i should pop the array elements and add them to total…seems to be more difficult than i anticipated

Your code so far

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

// Only change code below this line

for (let i = 0; i <= myArr.length ; i ++) {

const total = myArr.pop(i) ; console.log(total)
  
}

Your browser information:

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

Challenge: Basic JavaScript - Iterate Through an Array with a For Loop

Link to the challenge:

You are not following the instructions:

Declare and initialize a variable total to 0

Also, pop does not take any arguments. Do you understand what pop does? Each iteration myArr is getting shorter yet i is getting higher. This is going to be a problem you will need to handle.

1 Like

yeah i tried to work off of memory