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

Ivan Rakic
Ivan Rakic
2,539 Points

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

let firstName = ("Ivan");
let lastName = ("Rakic");
let role = "developer";
let msg = firstName "" + lastName "" + ":" + role;

1 Answer

Bella Bradbury
.a{fill-rule:evenodd;}techdegree seal-36
Bella Bradbury
Front End Web Development Techdegree Graduate 32,790 Points

Hello Ivan! There's just a few differences to get you passing this challenge. Your first three lines of code will technically pass you, though you don't need to put the strings in parenthesis. The reason that the string is in a parenthesis in the video is because it's the string for the prompt method. This code should highlight the difference more:

let promptString = prompt("Here is the text that will pop up on the page!");
let normalString = "Here is a simple string that doesn't need parenthesis to do it's job!";

As for errors that will keep you from passing this challenge, let's look at the last line of your code and re-build it together!

  • The first part of your line is correct, up to the first quotation marks. Good job setting up the variable!

    let msg = firstName
  • The first thing we're going to want to change is add a plus sign after firstName. A string won't automatically concatenate so adding in a + in between each piece is necessary.

    let msg = firstName +
  • Next let's look at what's in the first set of quotation marks that you've included. Your current code has an empty string, which means it won't actually do anything. To add a space into the message we have to put a space in the between the quotation marks.

    let msg = firstName + " "
  • You've added the last name! So let's leave that just as it is.

    let msg = firstName + " " + lastName
  • Now for the quotation marks after lastName. If we wanted to add a space here too, we'd have to add another plus sign in between the variable and the quotation marks and add a space in between the quotation marks, but if we look at the example we'll see that we actually don't want to add a space here. Let's take out that second set of quotation marks and go straight into adding the colon!

    let msg = firstName + " " + lastName + ":
  • From here there's just one last change to implement to pass the challenge! Looking one more time at the example shows us that we want a space after the colon instead of before. Let's go ahead and add a space after the colon (in the same string), as well as the closing quotation mark and the rest of the line.

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

And there we have it! Above is the finished line of code to add to your project :) Hopefully walking through it together helps you to better understand how concatenation works. Happy coding!