Why is my for loop stuck on the second option?
You need to change if (i = 0)
to if (i == 0)
. In Javascript and many other programming languages, =
means assignment, but ==
means comparison. Since you're trying to compare i
to an integer, you want the comparison operator, rather than the assignment operator.