Iterate Loop exercise not making sense

Iterate Loop exercise not making sense
0.0 0

#1

Tell us what’s happening:
It seems I’m following the example exactly, but I’m not getting it right somehow… Am I missing something?

Your code so far

// Example
var ourArray = [];

for (var i = 0; i < 5; i++) {
  ourArray.push(i);
}

// Setup
var myArray = [];

// Only change code below this line.

for (var a = 1; a < 5; a++);
myArray.push(a);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3355.0 Safari/537.36.

Link to the challenge:


#2

Never mind I figured it out. I was missing brackets - ___ -


#3

Actually, it had nothing to do with adding brackets. You had two issues:

  1. The instructions wanted you to push the values 1 through 5 onto myArray and you were attempting to push the values 1 to 5 (1 through 4) onto myArray

  2. Also, you had a semi-colon at the following line:

for (var a = 1; a < 5; a++);

That semi-colon made JavaScript disconnect the next line from the for loop, so the for loop still executed. Then after the for loop was finished, the variable a had value of 5, so the myArray.push was only executed one time with myArray only have one element (the value 5) in it.


#4

Thank you! I see it now.