Tell us what’s happening:
I’ve completed the challenge, however, this was achieved simply by mimicking the example that is already there. I don’t really understand exactly what is happening here, or why it equals 20.

So, ‘total’ initially equals 0

In the setup of the loop, ‘x’ also starts at 0

If ‘x’ is less than the length of the array, then increase ‘x’ by 1
So, the length of the array is 5, as that is how many elements are contained within it (unless I’m totally misunderstanding this). This is where it all becomes unclear to me.
My understanding of the section in bracelets is that it will take the value of ‘x’ as the index of the array, then add the value of that index to ‘total’.
So, the way I see the first time round the loop is;

‘x’ starts as 0

The array length is 5, and ‘x’ is 0, so increase ‘x’ by 1
Then we go into the bracelets.
 myArr[x] should resolve to index 1 of the array, which is 3, which then gets added to the variable of ‘total’.
If the above were to play out, then surely the value of ‘x’ would be equal to 5 long before the value of ‘total’ reached 20. Obviously my understanding is off somewhere, but I don’t quite see where.
Your code so far
// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;
for (var i = 0; i < ourArr.length; i++) {
ourTotal += ourArr[i];
}
// Setup
var myArr = [ 2, 3, 4, 5, 6];
// Only change code below this line
var total = 0;
for (var x = 0; x < myArr.length; x++) {
total += myArr[x];
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascriptalgorithmsanddatastructures/basicjavascript/iteratethroughanarraywithaforloop