JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops For Loops

AJ Zhang
AJ Zhang
8,945 Points

why did it print out all the divs instead of just the last one?

I don't quite understand why it printed all the divs. Shouldn't it just print the last value returned? Thanks.

2 Answers

It prints out all the divs because each time the for loop iterates it adds another <div> containing that "i" value to the array html. once the loop is complete it then writes out that html array in its entirety.

Hope that helps make sense of it,

Dylan

AJ Zhang
AJ Zhang
8,945 Points

I got it! Thank you!