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 Basics Working with Strings Combine and Manipulate Strings

task 2

can anyone help please

app.js
 firstName=("Malcolm");

 lastName=("Mowlam");
 role = 'developer';
 firstName=("Carlos");

 lastName=("Salgado");
 role= 'developer';
 msg =  'firstname ' + 'lastname'  + 'role';
console.log = msg

1 Answer

Tomasz Grodzki
Tomasz Grodzki
8,130 Points

You have to concatenate a variables with strings. You cannot write firstName in quotes. When you write it in quotes it's treated just like string 'firstName' without any refer to variable firstName.

So if you want to concatenate variables with strings you have to write sth like this:

let msg = firstName + ' ';

In this example above you have value from firstName ( because it's without quotes so it refers to variable with this name) and then you have added a space (because this sign is added with quotes).

If we change it to

let msg = 'firstName' + ' ';

Now in msg we have just series of signs: 'firstName '. firstName is in quotes so it's treated just like normal series of signs (without any refer to any variable).

And you have to remember to add colon before role.

BTW what is this?

console.log = msg

Shouldn't it be?

console.log (msg)