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 trial

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

jiwan gurung
jiwan gurung
4,248 Points

why is the variable html doing?and what is the purpose of div?

why is the variable html doing?and what is the purpose of div?

Tina Gee
Tina Gee
3,296 Points

if you experiment with the code a bit and change the <div> tags to <p> tags or <h1> tags and then view the browser, you might be able to get a better understanding of why it is that the <div> tag was used. hope this helps!

1 Answer

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

The html variable is used to contain html elements which can then be shown inside the web page with document.write(). In this instance, the html variable is used to contain a div element. Using the for loop, a div element is created for each number, 1 through 10. For each for loop iteration, the html adds a div element containing a number up to and including 10. For the example used in the video, the div is styled to be a circle, but a div is just a HTML wrapper to contain child elements.