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 trialSandra Vu
3,525 PointsPlease explain the logic of the sequence of adding the HTML tags of <ol> and <li> in JS code
Please help me understand of the logic of adding HTML tags as in the code below:
var listHTML = '<ol>'; for (var i = 0; i<list.length; i+= 1) { listHTML += '<li>' + list[i]+'</li>'; } listHTML+= '</ol>';
Any recommendation for reading about adding HTML elements in JS code?
Many thanks
1 Answer
Steven Parker
231,275 Points
The tag <ol>
begins an ordered list, and <li>
begins a list item.
So this code starts an ordered list, creates a number of list items inside it with start and end tags for each one, and finally completes the ordered list with the end tag.
What's being done here is pretty straightforward HTML creation. If you're unfamiliar with the HTML code itself, you might enjoy the course on HTML.
Sandra Vu
3,525 PointsSandra Vu
3,525 PointsThanks Steven. I shall look at the course on HTML
Henry Garmendia
Courses Plus Student 11,762 PointsHenry Garmendia
Courses Plus Student 11,762 Points@Steve you are a Beast brother with those points