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

Ricky Redman
Ricky Redman
7,520 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,880 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,364 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,520 Points

Thanks Mark and Ana these were helpful explainations