freeCodeCamp Challenge Guide: Concatenating Strings with Plus Operator

Concatenating Strings with Plus Operator


Hints

Hint 1

Concatenate means to link together. Think of the ‘+’ operator like a chain linking strings together; add the strings just like you add numbers. Make sure your spelling is correct! Take note of spaces between words.

const str = "Good " + "job!"; // It says "Good job!"
const abc = "Good" + "job!"; // It says "Goodjob!"
14 Likes

I can’t figure out what’s wrong with my code. I have:

var myStr = "This is the start." + "This is the end.";

Screenshot

I can’t get that first one. The only difference I can see is the quotation marks, which I tried “escaping” and removing but that doesn’t work.

Any idea how I can fix it? Hopefully it’s not just something that’s staring me in the face :yum:

27 Likes

It is something that is staring you at the face after all, check the strings you have to put together and you will eventually notice that you are missing a white space, where it is, is up to you to find out :wink:

40 Likes

Got it, that seems like a strange place for a space, heh. Thanks!

12 Likes

Why can’t I solve this by this way? Afterall we can add strings too.

1 Like

The concatenating strings are like adding two “strings” + “together”

It says "Build myStr from the strings “This is the start. " and “This is the end.” using the + operator.”

var myStr = “This is the start.” + “This is the end.”;

By doing it this way you don’t have to define the “string” as a variable and then call on that variable when adding str1 + str2

5 Likes

I am trying to finish this assignment but I think there is a bug… The is identical to the example and I read the direction, but I am not sure why it’s not working. I watch this video on youtube and this person has the same code.

My code:

/ Example
var ourStr = "I come first. " + “I come second.”;

// Only change code below this line

var myStr = “This is the start.” + “This is the end.”;

It is saying that incorrect… “myStr should have a value of This is the start. This is the end.” and that is exactly what I have.

Same, I am watching Coding Tutorials 360 and he put the exact code but it still giving me this error.

1 Like

Turns out its not a bug, you have to put a space between the start and the double quote.
So the code will be like this var myStr = "This is the start. (space) " + “This is the end.”;

Just copy and paste this code if you still don’t understand

// Example
var ourStr = "I come first. " + “I come second.”;

// Only change code below this line

var myStr = "This is the start. " + “This is the end.”;

Thank me later :slight_smile:

39 Likes

it doesnt work why? i dont know

2 Likes

Show me the screenshot of your thing

2 Likes

thank you bro :smile:

Should look like this with a space after start.

var myStr = "This is the start. " + “This is the end.”;

5 Likes