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

combining string challenge

i dont know wha else to do

let firstName = "keron"; let lastName = "veal"; let role = 'developer'; let msg; msg += firstName; msg += lastName; msg += role;

3 Answers

Keron, Steven is correct, this challenge is asking that you concatenate the strings together into a format like this: "keron veal: DEVELOPER". What you have now just creates a string that looks like this: "undefinedkeronvealdeveloper". So you'll have to do a couple of things to your code here; add formatting to your final msg string to include the spacing and ':' character AND convert the value of the role string to uppercase. Like so,

let firstName = "keron"; 
let lastName = "veal"; 
let role = 'developer'; 
let msg = firstName + ' ' + lastName + ': ' + role.toUpperCase(); 

Notice that I removed the 'let msg;' code and did not perform a '+=' on it. If you left that in then you'd get something like this: 'undefinedkeron veal: DEVELOPER' as you'd just be appending the value of 'undefined' to the desired message since the 'let msg;' code results in a value of 'undefined'.

Thanks dude i was adding ' ' in a few of my attempts but i guess i was adding them in the wrong spot i passed it now with everyone help from here

You forgot to take away the semicolon after let msg.
let firstName = "keron"; let lastName = "veal"; let role = 'developer'; let msg // ; // msg += firstName; msg += lastName; msg +=

Steven Parker
Steven Parker
231,153 Points

You didn't provide a link to the challenge, but I seem to recall that it wants some spacing and/or punctuation in addition to the words in the final string.

Also, you can't use the "+=" operator until after you have assigned something to the variable you are appending to.

A typical solution would perform all the concatenation on one line, but something like this might also work:

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