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

Collin Smith
Collin Smith
240 Points

string challenge

I don't know what I'm doing wrong here. Ive done "firstName ' + ' lastName".

app.js
let firstName = 'Collin';
let lastName = 'Smith';
let role = 'developer';
let msg = "firstName ' + ' lastName ' + ' role";

3 Answers

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 38,004 Points

You need to concatenate strings. To do this in JavaScript you simply add the string together. So if you have variables string1 and string2 and wanted to create a new string with a space in between the 2 strings you would do this

let msg = string1 + " " + string2;

for the challenge use this same format and replace string1 and string 2 with the variables from the challenge. Also be careful with the colon. There needs to be a space after it like this ": ".

Collin Smith
Collin Smith
240 Points

let msg = firstName + ' ' + lastName + ':' (+) role (+) '.'; The "+" in parentheses were missing from the concatenated string.

Mark Sebeck
Mark Sebeck
Treehouse Moderator 38,004 Points

Did you get it to pass? Looks like you are missing a space after the ":" and have an period at the end that the challenge didn't ask for.

Collin Smith
Collin Smith
240 Points

Yes it passed. All the spacing is right in the challenge. Now im trying to figure out how to get "role" to uppercase. Mind helping me with that as well? I cant figure out where to put .toUpperCase() with out changing the role variable. I've tried adding other variables to the challenge to still have "role" in "let msg = ....." I've also tried adding .toUpperCase() to the msg string and got nothing. I cant find my answer on google.

Mark Sebeck
Mark Sebeck
Treehouse Moderator 38,004 Points

Adding .toUpperCase() after the role variable in the msg should work. If not post your code.

Collin Smith
Collin Smith
240 Points

let firstName = 'Collin'; let lastName = 'Smith'; let role = 'developer'; let msg = firstName + ' ' + lastName + ':' + role.toUpperCase() + '.'; console.log(msg); I checked the spacing to make sure it was still good, but Im getting an error. Do I need a space between role and .toUpperCase.

Mark Sebeck
Mark Sebeck
Treehouse Moderator 38,004 Points

The line:

console.log(msg);

is great for troubleshooting. But not so great for the challenge. Just delete it and it will pass. The challenges are looking for exactly what they ask. Any additional code confuses them.

Collin Smith
Collin Smith
240 Points

It worked. Spacing was the issue with ':'. I needed to change it to ': ' to get it to work.

Mark Sebeck
Mark Sebeck
Treehouse Moderator 38,004 Points

Awesome!! Strings have to be exact for the challenges.