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

Jeanene Cannon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeanene Cannon
Full Stack JavaScript Techdegree Graduate 15,407 Points

I am stumped! Please help: Below role, create a new variable named msg that combines the firstName, lastName and role va

Below role, create a new variable named msg that combines the firstName, lastName and role variables to create a string

app.js
let firstName = "Jeanene";
let lastName = "Cannon";
let role = "developer";
let msg = "firstName + ''lastName: + ''role '.' ";

7 Answers

Jeanene Cannon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeanene Cannon
Full Stack JavaScript Techdegree Graduate 15,407 Points

firstName = "Jeanene"; let lastName = "Cannon"; let role = 'developer'; var msg = 'firstName + ' ' lastName: + ' ' role + '.' ';

I keep getting messages to pay attention to spacing but everything I've tried has been wrong. I can't move forward until I get this right. please advise.

Rick Gleitz
Rick Gleitz
47,876 Points

Hi Jeanene,

It's all in the formatting of that last line. First, the variables don't have quotes around them. The whole statement doesn't need quotes either. There are a lot of + signs connecting everything together. Also the colon needs to go in a set of quotes along with a space. The previous set of quotes needs a space in it as well. And lastly, don't do anything with the period at the end. It has nothing to do with the challenge, it's just part of the challenge instructions.

It should follow this format: let msg = variable + 'space' + variable + ':space' + variable;

Hope this helps!

Jeanene Cannon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeanene Cannon
Full Stack JavaScript Techdegree Graduate 15,407 Points

Yes it does help. Thank you so much for taking the time to help me. I just started learning this stuff a few days ago so it's a huge learning curve for me. Thank you again - going to try to implement your suggestions and see how they work out for me.

Jeanene Cannon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeanene Cannon
Full Stack JavaScript Techdegree Graduate 15,407 Points

So this ended up being the answer...that colon with the space really took me a minute to figure out..but thank you to the folks who helped me to figure this out.

let msg = firstName + ' ' + lastName + ': ' + role;

let msg = firstName + ' ' + lastName; would set msg to be the value of firstName followed by a space followed by the value of lastName. The variables firstName and lastName should not be surrounded by quotes, since you want their values and not their names. There should be a + separating each of the values.

Using string interpolation, this would give the same result as

let msg = `${firstName} ${lastName}`;
Jeanene Cannon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeanene Cannon
Full Stack JavaScript Techdegree Graduate 15,407 Points

Thank you so much. This makes total sense...I did actually try it without quotations as well...but I guess I had other errors and nothing worked. This was like my third day doing anything like this so I am still trying to take all this in. Now we were learning about string concatenation - don't think I've learned string interpolation yet with the dollar signs. But thank you because just your explanation helps me to remember how it should be formatted/verbalized/spaced and when/why quotations are appropriate. Thank you for that.