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

Isaac Cheung
Isaac Cheung
1,553 Points

I have added a space between 'firstname' and 'lastName' but why it shows that my answer is wrong?

app.js
let firstName = "Vincent";
let lastName = "Cheung";
let role = "developer";
let msg = "firstName " + "lastName:" + "developer."

1 Answer

Juan Luna Ramirez
Juan Luna Ramirez
9,038 Points

I can't see the challenge but it seems to be a confusing one. But in your case, the msg variable is currently this, "firstName lastName: developer". You have to remove the quotes from the variable names in order to use the actual variable value.

notice have I have to also add any other characters, like the space, semicolon & space, and period at the end, that I want in the final string

let msg = firstName + " " + lastName + ": " + role + "." // result in "Vincent Cheung: developer.

Another way is to use string interpolation. This to me is easier because anything inside the ${} will be evaluated to whatever the variable value is. Everything else is just literally whatever character you use.

let msg = `${firstName} ${lastName}: ${role}.` // result in "Vincent Cheung: developer.

Hope this helps