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

James Zwar
James Zwar
11,737 Points

Having an issue with message+=

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>';

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

print(message);

If I run this - I get the message displayed - but if I uncomment the "message+=" line no message is displayed. In the console it says there is an: Uncaught SyntaxError: Unexpected identifier

James Zwar
James Zwar
11,737 Points
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>';


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

print(message);

Edit (formatting)

2 Answers

Colin Bell
Colin Bell
29,678 Points

You just forgot to concatenate.

function print(message) { console.log(message) }

var message = 'Hello. My name is ' + person.name + '';

message += 'I live in ' + person.country + '';
//                      ^                ^
print(message);
James Zwar
James Zwar
11,737 Points

Oh right - thanks very much Colin!