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 (Retired) Storing and Tracking Information with Variables Combining Strings

Erika Green
seal-mask
.a{fill-rule:evenodd;}techdegree
Erika Green
Front End Web Development Techdegree Student 2,514 Points

Why put a period at the beginning of a string.

Sorry if I missed this but some of the strings have periods at the begining... i.e. message += ". Please come again, when you want to learn some more.";

Is this to separate the sentence by a new line instead of a space?

4 Answers

Marileen Mennerich
Marileen Mennerich
1,161 Points

They are concatenating several pieces of text into one long String. In this case, they also use the "visitor" variable which holds the name typed into the prompt. The . at the beginning of a new piece of text is simply there to end the sentence that came before. So if visitor = Erika, then "Hello " + visitor + ". Nice to meet you." -> "Hello Erika. Nice to meet you."

As you see, the period is only part of the preceding sentence.

Erika Green
seal-mask
.a{fill-rule:evenodd;}techdegree
Erika Green
Front End Web Development Techdegree Student 2,514 Points

Okay I think I got it. visitor represents the variable for my name so I can't add a period at the end of it. So the period is added at the beginning of the next string followed by a space.

Makes perfect sense now.

Thank you!

Christina Perez
Christina Perez
2,605 Points

This was really helpful. It would have been helpful for that to had been addressed in the video. It can be confusing when new things are added without explanation. Thanks for this tidbit.

It is just part of the sentence. Like welcome to treehouse. Hope you are having fun coding. The "." is inside the quotes so it is part of the sentence so it does not look like this. Welcome to treehouseHope you are having fun coding

It is just part of the sentence. Like welcome to treehouse. Hope you are having fun coding. The "." is inside the quotes so it is part of the sentence so it does not look like this. Welcome to treehouseHope you are having fun coding

Jeremy Frimond
Jeremy Frimond
14,470 Points

The "." is the code used to concatenate or combine strings of text together. For example if i wanted to combine "Hello, how are you today" with "The weather outside is delightful" I would have to concatenate these strings with the "."

 document.write( "Hello, how are you today" . " " . "The weather outside is delightful."  );

This will output Hello, how are you today The weather outside is delightful.

It would appear that there are periods at the beginning of the sentences but they are really the combining tool used it code to "smoosh" things together.

FYI the blank quotes in the middle are to add a space between the two statements.

Marileen Mennerich
Marileen Mennerich
1,161 Points

I think this is PHP syntax and not applicable in this case ;)

That is PHP syntax, as Marileen said. You use + signs for concatenation, not a period.

Document.write is not a part of PHP syntax, however.