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 trialenoch okyere
4,681 PointsWhat is wrong with this syntax? let msg = firstName + ' ' + lastName + ':' + ' ' + role + '.';
let firstName;
let lastName;
let role = 'developer';
let msg = firstName + ' ' + lastName + ':' + ' ' + role + '.';
firstName += "Enoch";
lastName += "Okyere";
4 Answers
Cameron Childres
11,820 PointsHey Enoch~
There's a couple issues here.
In the first two lines you're declaring variables but you aren't giving them any value which defaults to them being undefined
.
On line 3 you build a message that accesses these variables, but they're undefined, so your message is set as: "undefined undefined: developer."
On the last two lines you're adding strings to the undefined variables, which then sets them to:
- firstName = undefinedEnoch
- lastName = undefinedOkyere
Note that this runs after you declare msg
, so the msg
variable remains unchanged.
Finally, the challenge wants you build a string that will look like "Carlos Salgado: developer". Notice that there is not a period inside this string.
To fix this you can declare the firstName
and lastName
variables with your first and last name from the start. You'll also want to removed the period from the msg
string. I've additionally combined ":" and " " in to ": " for simplicity:
let firstName = 'Cameron';
let lastName = 'Childres';
let role = 'developer';
let msg = firstName + ' ' + lastName + ': ' + role;
If you wanted this to work with the addition assignment operator to build the variables you could initialize firstName
and lastName
with empty strings to avoid them being undefined:
let firstName = '';
let lastName = '';
firstName += 'Cameron';
lastName += 'Childres';
let role = 'developer';
let msg = firstName + ' ' + lastName + ': ' + role;
LaToya Legemah
12,600 PointsI ran your code and did not receive an error message. What error are you receiving? Your syntax for msg is correct.
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 PointsHi Enoch,
let firstName = 'Enoch';
let lastName = 'Okyere';
let role = 'developer';
let msg = firstName + ' ' + lastName + ': ' + role;
I think you need to assign the firstName and lastName variables before the msg variable so they can be used in the msg variable.
Also double check your msg variable, it has to match exactly the output specified in the challenge. I think you have an extra "." at the end.
Happy Coding!
enoch okyere
4,681 PointsThank you all so much I was having trouble getting past the challenge question. Now I have gotten through it! Thanks for all of your helpful advice means a lot!!
Yoan Herrera
21,137 PointsYoan Herrera
21,137 PointsTry assigning the values for first and last name with the = sign and not with +=