Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

Blake Piper
Blake Piper
1,223 Points

Why suddenly all this HTML?

i was on board with all the arrays and loops and was starting to understand things. seems like out of nowhere he just starts throwing around HTML code like im suppose to know what it means? '<ol>' '<li>'. never seen that before and its really throwing me for a loop (pun intended).

function printList( list ) { var listHTML = '<ol>'; for ( var i = 0; i < list.length; i += 1){ listHTML += '<li>' + list[i] + '</li>'; } listHTML +='</ol>'; print(listHTML);

makes it harder for me to understand whats going on when hes throwing around terms and html stuff that i have no clue about. did i miss something?

5 Answers

8,113 Points

If you are confused by the HTML, I would recommend taking the HTML basics course after you finish the JavaScript course you are currently taking, but until then don't worry too much about it and just copy what the teacher writes. If you feel that HTML is being used a lot in this course, however, you may want to ask Support to add the HTML Basics course to the prerequisites for this course.

They should definitely add it as a prerequisite :P I know HTML but if I haven't, I would be very annoyed.

Even though, checking the comments in the first lessons, people say we must take the HTML Course from the 'Tracks'. But this Tech Degree should warn you at the beginning as well. Maybe add another step that says 'Go learn HTML before proceeding' . Lol.

8,113 Points

Basically what you're encountering here is the DOM, or Document Object Model. You interact with DOM whenever you change HTML (or CSS) using JavaScript. It is probably one of the things JavaScript is most commonly used for, so it is definitely something to explore more. Treehouse has a great course on it I took this summer that explains all the basics, so I would highly recommend starting your studying there. It can be found at https://teamtreehouse.com/library/javascript-and-the-dom-2. Hope this helps!

Thank you very much

8,113 Points

Any time. Glad I could help!

I think that this is not a question of html, but a question of interaction between JavaScript and Html. Could someone tell me what the name of this interaction is, so that I can find information about it to study.

Connor Sayers
Connor Sayers
1,515 Points

<ol> - This stands for 'Ordered List', any list item within this tag will be assigned a number in order e.g. 1. 2. 3. 4.

<li> - You place this tag inside the Ordered List to show each individual list item.

EXAMPLE CODE: <ol> <li>List Item One</li> <li>List Item Two</li> <li>List Item Three</li> </ol>


  1. List Item One
  2. List Item Two
  3. List Item Three

While you don't need to know HTML to learn JavaScript, it's a good idea to understand it as they work hand in hand. I agree with varlevi's comment when they say take the HTML basics course as it will teach you the basic syntax.

Tomasz Furmanczyk
Tomasz Furmanczyk
Web Development Techdegree Student 16,079 Points

Elena I think what you're asking when you mention "interaction" between HTML and JAVASCRIPT is that this is a form of concatenation

//When you see this concept of concatenation

var a = "The stranger ";

var b = " wants a hug.";

var c = a + b;




//It's very similar to this concept just adding in a loop:

//variable including the start of a HTML ordered list tag var listHTML = '<ol>';

//loop for ( var i = 0; i < list.length; i += 1){

//concatenating to the variable adding each listed item and surrounding it with list open and closed tags listHTML += '<li>' + list[i] + '</li>'; }

// closing with the ordered list tag listHTML +='</ol>';

//Then printing out the result of the variable print(listHTML);