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 trialErika Green
Front End Web Development Techdegree Student 2,514 PointsWhy 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
1,161 PointsThey 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.
Stephen Petruzziello
7,084 PointsIt 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
Stephen Petruzziello
7,084 PointsIt 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
14,470 PointsThe "." 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
1,161 PointsI think this is PHP syntax and not applicable in this case ;)
Erika Green
Front End Web Development Techdegree Student 2,514 PointsIf this is PHP that's great...I will be learning this too so this is good to know.
Thank you!
Marcus Parsons
15,719 PointsThat is PHP syntax, as Marileen said. You use + signs for concatenation, not a period.
Marcus Parsons
15,719 PointsDocument.write is not a part of PHP syntax, however.
Erika Green
Front End Web Development Techdegree Student 2,514 PointsErika Green
Front End Web Development Techdegree Student 2,514 PointsOkay 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
2,605 PointsChristina Perez
2,605 PointsThis 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.