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

Jeffrey Vierra
Jeffrey Vierra
25,404 Points

Javascript Basics: Working with strings/Combine and manipulate strings exercise. (I’m STUCK).

I’m stuck on this exercise. The question is:

Challenge Task 2 of 3 Below role, create a new variable named msg that combines the firstName, lastName and role variables to create a string like “Carlos Salgado: developer”.

My code is as follows:

let firstName = " FirstName";
let lastName = "LastName" + ":";
let role = " developer";
let msg = firstName + " " + lastName + role;  

My result is:

FirstName LastName: developer.

Which is correct. However the error I get is

Bummer: There should not be a ":" at the end of your lastName string value.

Please advise.
Thank you in advance

12 Answers

Ignacio Rocha
Ignacio Rocha
7,462 Points

your answers is right in the way that you declare the msg variable but the values of the other variables are wrong. The challenge is asking you to create the message "Carlos Salgado: developer" literally that is the answer.

let firstName = " Carlos";
let lastName = "Salgado";
let role = "developer";
let msg = firstName + " " + lastName + ": " + role; 

Also when declaring a variable make it more simple if you need to reuse the lastName variable and need only the last name it will also call the colon punctuation, and the role erase the space because you may need it to so keep it clean.

thank you brilliant

Thanks Ignacio Rocha! above code is the right one.

Tom Nguyen
Tom Nguyen
33,500 Points

This is what I used to pass:

app.js
let firstName = 'team';
let lastName = 'treehouse';
let role = 'developer';
let msg = firstName + ' ' + lastName + ": " + role.toUpperCase();

Thank you Tom, I had similar problem but your help sorted me out.

let firstName ="X"; let lastName = "Y"; let role = 'developer'; let msg = firstName + " " + lastName +" " + ": " + role;

let firstName = " FirstName"; let lastName = "LastName"; let role = " developer"; let msg = firstName + " " + lastName +": "+ role.toUpperCase();

I’m having the same trouble with this task as well. None of the suggested answers seem to work can anyone help me clear this one up

Jeffrey Vierra
Jeffrey Vierra
25,404 Points

You guys are awesome! Thank you

Very useful. Thanks

I have tried the solution above, but it doesn't work. What is the exact solution to this?

Below role, create a new variable named msg that combines the firstName, lastName and role variables to create a string like "Carlos Salgado: developer".

HINT: Pay close attention to the spaces in the string.

let firstName = " Carlos"; let lastName = "Salgado"; let role = "developer"; let firstName = "Carlos" + let lastName = "Salgado" + let role = "developer";

Thanks!!

Ignacio Rocha
Ignacio Rocha
7,462 Points

Actually my answer was right but thanks to your hint I just realize that I made a mistake, I typed

let firstName = " Carlos" //Notice the space at the beginning of the string.

To answer your question about the exact solution you just need to create a variable called msg like so

let firstName = "Carlos";
let lastName = "Salgado";
let role = "developer";
let msg = firstName + " " + lastName + ": " + role; 

Then the last part they task you to create the same message but with the role in upper case it should be like this

let firstName = "Carlos";
let lastName = "Salgado";
let role = 'developer';
let msg = `${firstName} ${lastName} : ${role.toUpperCase()}` 
/*this type of string concatenation is called template literals
is a much cleaner way to concatenate string and variables*/

If anyone want to learn more about Template Literals here is the Workshop:

https://teamtreehouse.com/library/introducing-template-literals

let msg = 'reginald' + ' ' + 'freeney:' + 'developer:'

Anyone else think the question itself was not clear? create a string LIKE "Carlos Salgado: developer". should be: create the string "Carlos Salgado: developer"

const firstName = 'Jade'; const lastName = 'Nguyen'; const role = 'developer'; const msg = firstName + ' ' + lastName + ': ' + role; I tried with this one, it work

Ayman Omer
Ayman Omer
9,472 Points

let firstName="ayman"; let lastName="omer"; let role = 'developer'; var msg; var masg = firstName + ' ' + lastName + ':'+ role ;