The numbers we use to access a certain value are called an “index”. Notice the “0” index refers to the first value in the array, the “1” index refers to the second value, and so on.
Back to the lesson you’re asking about, it explains that a common task is to “loop through” an array, accessing each of its values in turn. In this lesson we want to use that technique to calculate the total of all the numbers in myArray.
Here’s the starter code:
const myArr = [2, 3, 4, 5, 6];
// Only change code below this line
And here’s the instructions:
Declare and initialize a variable total to 0. Use a for loop to add the value of each element of the myArr array to total.
So, here are the steps:
declare a variable named total and assign it the value 0
using a for loop, access each value in myArray in turn, and add it to total
Notice, declaring total needs to happen before the for loop.