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 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,306 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,873 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.