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
rocky roy
556 PointsWhy is code is not working ?
Why is code is not working, same code as tutorial.
var person = {
name : 'Sarah',
country : 'US',
age : 35,
treehouseStudent : true,
skills : ['JavaScript', 'HTML', 'CSS']
};
function print(message) {
var div = document.getElementById('demo');
div.innerHTML = message;
}
var message = '<p> My Name is + person.name + </p>';
message += '<p> I am '+ person.age +' year old </p>';
message += '<p> I live in '+person.country;
person.country = 'India';
message += '<p> But now i live in '+ person.country + '</p>';
message += '<p> My skills are '+ person.skills.join(', ') + '</p>';
message += '<p> I have total '+ person.skills.length + ' </p>';
print(message);
3 Answers
Steven Parker
243,318 PointsIt looks like you are missing some quotes on this line (here it is with the quotes added):
var message = '<p> My Name is ' + person.name + ' </p>';
I did not get any console errors either way.
Simon Coates
28,695 PointsI just tried it. I had to create a HTML element with an id of "demo", then ran the code. It worked fine, apart from '<p> My Name is + person.name + </p>'; which should be '<p> My Name is '+ person.name + '</p>';
rocky roy
556 PointsBut when i am trying , it's shows error in the console. it's shows .
div.innerHTML = message; (nunn)
Simon Coates
28,695 Pointsyou have an element on the page with an id of "demo"? otherwise the div variable will be null.