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 Data Using Objects Accessing Object Properties

I didn't understand confused

I didn't understand function print(message) { var div = document.getElementbyId("output"); div.inner.HTML = message; }//please help me==========================================================

Alexandra Edwards
Alexandra Edwards
4,686 Points

What are you having trouble with about this function? Are you wondering why he is using it in the video or are you having trouble with it working?

5 Answers

This is the complete function:

print(message) {
    var div = document.getElementbyId("output"); 
    div.inner.HTML = message; 
}

  • print Is the name of the function
  • (message) the parameter that your are sending to the function

And these are the arguments:

var div = document.getElementbyId("output"); 
div.inner.HTML = message; 
  • div is just the name of the variable.
  • document.getElementById is a method telling the function to locate a certain HTML element in the document (In this case, with the id ="output").
  • innerHTML is the method used to insert something into that HTML element ( In this case, the var message.)

Great breakdown! I too was confused. Thanks!

Alexandra Edwards
Alexandra Edwards
4,686 Points

This can definitely be a confusing one. There is a really good explanation on this page here in his ebook, JavaScript & JQuery: The Missing Manual, page 103.

This print function is a replacement for using the document.write() method all the time, so you can just call the print function whenever you need it. He named it print but you can name it anything.

Does this help make it a little more clear?

I was not aware Dave had an eBook. Thanks for the tip.

Bryan Land
Bryan Land
10,269 Points

In the last section where we went over arrays, the instructor finally switched over to using a more modern method of updating information in the DOM... Here is a link to that video: https://teamtreehouse.com/library/build-a-quiz-challenge-part-2

Yeah I don't understand why he is using it in the video and how it works

Teacher Russell
Teacher Russell
16,872 Points

One thing I know from experience here, is to be patient, and don't skip videos, or you will be confused. A lot of information is covered very quickly in these short little videos, but it's all there. Watch everyone carefully, listen to every word and take notes after a couple of listens. It took me a few watches to get it all, including that function, but if you study the earlier JS basics course, and watch all videos in this course preceding this one, you'll figure it out.