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 trialJeffrey Vierra
25,404 PointsJavascript 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
7,462 Pointsyour 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.
Tom Nguyen
33,500 PointsThis is what I used to pass:
let firstName = 'team';
let lastName = 'treehouse';
let role = 'developer';
let msg = firstName + ' ' + lastName + ": " + role.toUpperCase();
Chinonso Umeanoikwa
Courses Plus Student 1,359 PointsThank you Tom, I had similar problem but your help sorted me out.
Fran ADP
6,304 Pointsput :
MOHAMEDALI AHMED
6,423 Pointslet firstName ="X"; let lastName = "Y"; let role = 'developer'; let msg = firstName + " " + lastName +" " + ": " + role;
jhon white
20,006 Pointslet firstName = " FirstName"; let lastName = "LastName"; let role = " developer"; let msg = firstName + " " + lastName +": "+ role.toUpperCase();
james presley
6,154 PointsI’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
25,404 PointsYou guys are awesome! Thank you
Sezare Miguel
9,229 PointsVery useful. Thanks
Sylvia Brombin
UX Design Techdegree Graduate 18,759 PointsI 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
7,462 PointsActually 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
Reginald Freeney
2,863 Pointslet msg = 'reginald' + ' ' + 'freeney:' + 'developer:'
Dave Huynh
4,047 PointsAnyone else think the question itself was not clear? create a string LIKE "Carlos Salgado: developer". should be: create the string "Carlos Salgado: developer"
Jade Nguyen
3,303 Pointsconst firstName = 'Jade'; const lastName = 'Nguyen'; const role = 'developer'; const msg = firstName + ' ' + lastName + ': ' + role; I tried with this one, it work
Ayman Omer
9,472 Pointslet firstName="ayman"; let lastName="omer"; let role = 'developer'; var msg; var masg = firstName + ' ' + lastName + ':'+ role ;
malcolm mowlam
3,856 Pointsmalcolm mowlam
3,856 Pointsthank you brilliant
Samuel Buta
2,403 PointsSamuel Buta
2,403 PointsThanks Ignacio Rocha! above code is the right one.