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

Ryan Morrison
Ryan Morrison
187 Points

Below role, create a new variable named msg that combines the firstName, lastName and role variables to create a string

app.js
let firstName ="Ryan";
let lastName = "Morrison";
let role = 'developer';
let msg = +firstName''+lastName+': '+role;

1 Answer

Close, but there's a few small issues here.

The first plus is unnecessary, and will actually be interpreted as "parse as number" so the first string will become a type of number, and therefore will become NaN. The solution is to not have the first +.

FirstName is directly followed by quotemarks, there actually need to be a + in between there. Also it seems you may have forgotten about the space in between the quotemarks.

In it's simplest form you can simply do firstName + lastName + role, of course, if you want spaces and other things you can do something like firstName + ' ' + lastName + ': ' + role

I follow you code exactly and get "Cannot read property '1' of null on every variation. This challenge has me baffled - have gone over he video's numerous times. Am I missing something here?

can not read property 1 of null? What?

What is your code that produces that error?

let msg = firstName + ' ' + lastName + ': ' + role;

or

let msg = `${firstName} ${lastName}: ${role}`;