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

codekudos
codekudos
15,316 Points

Uncaught TypeError: Cannot set property 'innerHTML' of null

// html file -- located in the body section of index.html

<div id ="output">

</div>

//javascript file

var person = {
    name : 'me',
    country : 'US',
    student : true,
    skills : ['HTML', 'JavaScript', 'CSS']
};

function print (message){ var outputDiv = document.getElementById('output'); outputDiv.innerHTML= message; }

var message = '<p> Hello. My name is ' + person.name + '</p>'; html += '<p> I live in' + person.country + '</p>'; print(message);

/*When I call the print function an Uncaught TypeError: Cannot set property 'innerHTML' of null. - I am not using workspaces */

Code Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.

      ```html
      <p>This is code!</p>
      ```

2 Answers

Your code is good, you are near! Just a typo. Correct your code, you wrote this:

html += '<p> I live in' + person.country + '</p>'; 

but now the good way is, you don't use in the code var html

message += '<p> I live in' + person.country + '</p>';