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 trialJeanene Cannon
Full Stack JavaScript Techdegree Graduate 15,407 PointsI 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
let firstName = "Jeanene";
let lastName = "Cannon";
let role = "developer";
let msg = "firstName + ''lastName: + ''role '.' ";
7 Answers
Jeanene Cannon
Full Stack JavaScript Techdegree Graduate 15,407 PointsI've also tried the last line as const msg and I've tried different spacing...nothing works
Jeanene Cannon
Full Stack JavaScript Techdegree Graduate 15,407 PointsI've also tried the += and var - still nothing, so confused.
Jeanene Cannon
Full Stack JavaScript Techdegree Graduate 15,407 PointsfirstName = "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
47,876 PointsHi 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
Full Stack JavaScript Techdegree Graduate 15,407 PointsYes 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
Full Stack JavaScript Techdegree Graduate 15,407 PointsSo 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;
jb30
44,806 Pointslet 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
Full Stack JavaScript Techdegree Graduate 15,407 PointsThank 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.