Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Working with Strings Combine and Manipulate Strings

Ricky Redman
Ricky Redman
7,300 Points

creating a new string combining variables firstName lastName and role

not sure what I'm missing from this code to complete the challenge

app.js
const firstName= 'Ricky';
const lastName= 'Redman';
const role = 'developer';
let msg= `firstName '+'lastName:'+'role.`;
Mark Casavantes
Mark Casavantes
2,866 Points

Hello Ricky,

I think you were confusing regular concatination with template literals.

let firstName = "Mark ";
let lastName = "Casavantes ";
let role = 'developer';
let msg = `${firstName} ${lastName} ${role}`

2 Answers

Anna Pichugina
Anna Pichugina
25,264 Points

Hi Ricky!

In your answer JavaScript is reading everything inside the backticks (`) as a string, including your variable names. Like Mark said, you can use template literals to interpolate your values into the string enclosed by backticks. Another solution that's a little simpler is simply to add strings (and your variables that contain string values) together like this:

let msg= firstName + ' ' + lastName + ': ' + role;
Ricky Redman
Ricky Redman
7,300 Points

Thanks Mark and Ana these were helpful explainations