Spacing with plus, equal and variables can someone explain why this is?

Why is it that spacing:

With the plus opperator

'My name is Alan,' + ' I concatenate.' 

this is correct but after the , of the first scentense comes no space to sollute it. and the second one we do have extra spacing. But to pass the lesson we need to do the next

`"This is the start. "` and  `"This is the end."`

Suddently after the . of the first scentense we need a extra space but in the last scentense there is none? where did all the spacing go?

Then we have the += operator but suddently all the rules change again with the last scentense.

And then we end with the (+) which is diffrend on the both scentense once again?

`"My name is "` and  `" and I am well!"`

Here we need to place a spacing at the first scentense and one before we start the last scentense.

Why does it change every single time? This is so confusing

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Safari/605.1.15.

Link to the challenge:

Hi, technically wether you put the space in the first string or in the second it’s irrelevant.
What you do with those operators you mentioned is a concatenation of strings. You get a new string made of the string you concatenated together and every character of those strings count.
Wether you do
let newString = 'hello ' + 'dude'; (space in the first string)
let newString = 'hello' + ' dude'; (space in the second string)
the value hold by newString will still be “hello dude” with only one space.
If you were to put the space in both strings, you would end up with 2 space characters in the newString (“hello
dude”), because each of them do count as a separate caracter.

Edit: I can’t seem to find the issue with the challange you linked. Can you give the link of the one in which you have found the problem?

Also notice that, while it’s technically correct to put the space either on the first or on the second string, it might be that the FCC check that those strings are defined in a particular way (that, for example, is the case of variables there were already given to you and that shouldn’t be modified).

1 Like and the upcoming 3 lessons

Empty space is nothing else as one specific character inside of a string. If we are concatenating two, three or more strings, we need to know where we want to have empty spaces. We can do it something like so: "string " + "otherString", "string" + " otherString",“string " + someVariable + " otherString”, "string" + " " + someVar +" " + "otherSomeText."

1 Like

Sorry, I didn’t notice it before. Basically between those 2 string there will go another string that, for example, holds a name.
Something like:

let myName = "Simone";
let resultString = "My name is "+myName+" and I am well!"

The value of resultString is “My name is Simone and I am well!”

1 Like