Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMir Ali
3,175 PointsWhy can't we use for increment operator? for var i=0;i<factBook.factsArray.count;i+1
?
2 Answers
Enrique Munguía
14,311 PointsBecause the expression
i + 1
results in a value of 1 if i starts at 0, but that value of 1 gets lost immediatly if it is not assigned to a variable. In order to increment i, the value must be assigned to i
i = i + 1
or its short equivalent
i++
Charles Zhang
2,032 PointsBecause then it will not be random, it will display the facts in the order you put them in the facts array.
Mir Ali
3,175 PointsMir Ali
3,175 Pointssays error ++ is not a binary operator