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 trialCollin Smith
240 Pointsstring challenge
I don't know what I'm doing wrong here. Ive done "firstName ' + ' lastName".
let firstName = 'Collin';
let lastName = 'Smith';
let role = 'developer';
let msg = "firstName ' + ' lastName ' + ' role";
3 Answers
Mark Sebeck
Treehouse Moderator 38,304 PointsYou 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
240 Pointslet 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
Treehouse Moderator 38,304 PointsThe 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
240 PointsIt worked. Spacing was the issue with ':'. I needed to change it to ': ' to get it to work.
Mark Sebeck
Treehouse Moderator 38,304 PointsAwesome!! Strings have to be exact for the challenges.
Collin Smith
240 PointsCollin Smith
240 Pointslet msg = firstName + ' ' + lastName + ':' (+) role (+) '.'; The "+" in parentheses were missing from the concatenated string.
Mark Sebeck
Treehouse Moderator 38,304 PointsMark Sebeck
Treehouse Moderator 38,304 PointsDid 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
240 PointsCollin Smith
240 PointsYes 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
Treehouse Moderator 38,304 PointsMark Sebeck
Treehouse Moderator 38,304 PointsAdding .toUpperCase() after the role variable in the msg should work. If not post your code.