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 trialMartin Bornman
Courses Plus Student 12,662 PointsJavaScript Object
My code is not running in the browser.And is exactly the same as instructor's.
var person = { name : 'Sarah', country : 'US', age : 35, treehouseStudent : true, skills : ['JavaScript', 'HTML', 'CSS'] };
function print(message) { var div = document.getElementById('output'); div.innerHTML = message; }
var message = '<p>Hello my name is ' + person.name + '</p>; print(message);
1 Answer
Erik McClintock
45,783 PointsMartin,
There are two possibilities that I see from glancing over your code here.
1) Make sure, of course, that you have HTML that includes a div with the ID of "output", since this is the element you're targeting and attempting to fill
2) In your var message
declaration, you're reopening the string after your insertion of person.name
. This is likely the culprit.
You have:
// notice after "person.name +" you have another single quote ( ' ), then your semi-colon. You're reopening a string with that character.
var message = 'Hello my name is ' + person.name + '; print(message);
Try:
// notice the extra single quote after "person.name" is removed. We close our string out with "person.name", then call our print function on the next line
var message = 'Hello my name is ' + person.name;
print(message);
Or, alternatively, if you want to follow the code from the video exactly, you would wrap that in paragraph tags:
// notice the <p> tags around the whole string, and that we make sure to close the string after the closing </p> tag
var message = '<p>Hello my name is ' + person.name + '</p>';
print(message);
Give that a shot and let me know if you're on your way or if there seems to be a different issue!
Erik
Martin Bornman
Courses Plus Student 12,662 PointsMartin Bornman
Courses Plus Student 12,662 PointsThanks Erik,I got it!!!You helped me a lot!!