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 trialGraham Patrick
8,294 PointsRather stuck on this question
Would any one be able to help me with this question , dont think im quite understanding
11 Answers
Riley Hilliard
Courses Plus Student 17,771 PointsKeith Kelly's answer(s) are awesome and helped you through your issue beautifully. Couldn't help but see that it looks like where your understanding got foggy was with concatenation. In this instance, think of Concatenation like you would adding words together to make a sentence. The "plus"operator in PHP is "." but in english that is the equivalent as an adding operator. That's all concatenation is! So if you think about building the sentence "The sky is a hue of blue!", if you were to build that with concatenation it could look something like this:
<?php
echo "The" . " " . "sky" . " " . "is" . " " . "a" . " " . "hue". " " . "of" . " " . "blue" . "!"
// The sky is a hue blue!
With variables you can change a value, so you could end up with something like:
<?php
$color = "red";
echo "The" . " " . "sky" . " " . "is" . " " . "a" . " " . "hue". " " . "of" . " " . $color . "!"
// The sky is a hue red!
$color = "green";
echo "The" . " " . "sky" . " " . "is" . " " . "a" . " " . "hue". " " . "of" . " " . $color . "!"
// The sky is a hue green!
$color = "burple";
echo "The" . " " . "sky" . " " . "is" . " " . "a" . " " . "hue". " " . "of" . " " . $color . "!"
// The sky is a hue burple!
Hope this helps a bit
Keith Kelly
21,326 PointsBasically it would look something like this:
$fullName = $firstName . ' ' . $middleName . ' ' . $lastName;
In that case you are combining or concatenating all of the individual name variables to create a full name.
Graham Patrick
8,294 Pointsok so by adding \n in there wouldnt vaildate
Keith Kelly
21,326 PointsAre you attempting to add the new line break to the end of the variable? I wouldn't put it in the variable itself, but in the echo command when you call the fullName variable.
Graham Patrick
8,294 Pointsim a little lost here and may need to research a little more , like "Use concatenation to add an exclamation point to the echo command after the fullName variable." this questions just stumps me
Keith Kelly
21,326 PointsWhenever you are concatenating you are simply combining bits of information into a single piece. For example in the above comment you would echo the following.
echo $fullName . '!';
So what is happening is that php will echo the full name of the person (first middle last) then using the period you are telling php to add the exclamation point after the name. So it would look like:
Keith Bryan Kelly!
Hope this helps.
Graham Patrick
8,294 Pointsahhhhh it makes sense now !! Thanks Keith
Graham Patrick
8,294 PointsKeith i added it the way you said and it was wrong "echo "The designer at Shirts 4 Mike shirts is named $fullName . '!'"; any ideas?
Keith Kelly
21,326 PointsOK, so you need to have "The designer at Shirts 4 Mike is" before the full name. It will be the same concept. You will echo the first statement then add a period to concatenate the $fullName variable and then concatenate the exclamation point. It would look like this:
echo 'The designer at Shirts 4 Mike is ' . $fullName . '!';
Make sure that you have a space after the word "is" before you close the quotes so that it is separated from the full name.
Let me know if this works for you.
Graham Patrick
8,294 PointsNope is not having any of it, If i use your version it says that code three isnt working and if i do it like : echo "The designer at Shirts 4 Mike shirts is named" $fullName .'!'.; it pulls any error
Keith Kelly
21,326 PointsIt looks like you have an extra period after the exclamation point. It is probably throwing the error because it is expecting another value to concatenate. Try removing that period.
Graham Patrick
8,294 PointsPHP Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in concatenation.php on line 9 PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in concatenation.php on line 9 thats the php error
Graham Patrick
8,294 Pointsecho "The designer at Shirts 4 Mike shirts is named" $fullName .'!'; like this?? it dosnt work
Keith Kelly
21,326 PointsYou are also missing the period between the "named" and $fullName. It should look like this:
echo "The designer at Shirts 4 Mike shirts is named " . $fullName . "!";
Graham Patrick
8,294 PointsSpot on ! Works thank you
Keith Kelly
21,326 PointsGlad I could help!
Graham Patrick
8,294 PointsThank you Riley That helped so much! Im sure i will get there soon! But its coming together!!
Graham Patrick
8,294 PointsGraham Patrick
8,294 PointsCreate a variable called fullName and assign it a value equal to the concatenation of the firstName variable, a space, the middleName variable, a space, and the lastName variable.