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
Marco Roman
5,527 PointsPHP - Concatenation Task 4/4
Hello, I keep messing this one up and can't seem to figure it out. i'v tried a bunch of different code but i'm not exactly which direction is right? This is my current code:
<?php
$firstName = "Mike";
$middleName = "the";
$lastName = Frog;
$fullName = $firstName . " " . $middleName . " " . $lastName;
echo "The designer at Shirts 4 Mike shirts is named $fullName . !;
?>
14 Answers
Randy Hoyt
Treehouse Guest TeacherThat little fragment looks correct. Do you have an echo in front of it?
Here's the code as I intended it to be written:
<?php
$firstName = "Mike";
$middleName = "the";
$lastName = "Frog";
$fullName = $firstName . " " . $middleName . " " . $lastName;
echo "The designer at Shirts 4 Mike shirts is named " . $fullName . "!";
?>
Though you could also write the last line as two lines:
echo "The designer at Shirts 4 Mike shirts is named ";
echo $fullName . "!";
Does that help?
Randy Hoyt
Treehouse Guest Teacher(1) You need to put all the pieces of text inside quotation marks.
This is correct:
$flavor = "Cookie Dough";
This is not correct:
<del>$flavor = Vanilla;</del>
(2) You have code that concatenates variables and pieces of text together for Mike's full name. That code is perfect:
$fullName = $firstName . " " . $middleName . " " . $lastName;
This code has a variable, then a piece of text, then a variable, then a piece of text, and then a variable. The concatenation operator (.) is not inside quotation marks; if it were, it would get treated like a period as a piece of text.
Your echo statement is not correct. It should be similar to the $fullName line, but it has fewer pieces: it should concatenate a piece of text, then a variable, and then a piece of text.
Does that help?
Craig London
4,883 PointsYour issue is mostly related to quote issues in a few places.
Marco Roman
5,527 PointsI can't figure this one out at all. I keep re-reading your post Randy and looking at my notes but this isn't sticking with me. I really thought that was correct. I'm stuck with this, on a new line:
$fullName . "!";
I have the variable then the concatenation (.) and my "!"
Marco Roman
5,527 PointsI am scratching my head trying to figure this out out. I added an echo at the beginning of $fullName so this s my code:
echo $fullName . "!";
Randy Hoyt
Treehouse Guest TeacherCan you paste your full code here?
Marco Roman
5,527 PointsRandy, here you go:
<?php
$firstName = "Mike";
$middleName = "the";
$lastName = Frog;
$fullName = $firstName . " " . $middleName . " " . $lastName;
echo "The designer at Shirts 4 Mike shirts is named $fullName;
echo "$fullName" . "!";
?>
Marco Roman
5,527 PointsSorry no "" with $fullName, it was a typo
Randy Hoyt
Treehouse Guest TeacherThe problem here is the echo statement with the text "The designer at ...". It starts with a quotation mark that tells PHP you are beginning a plain piece of text ... but there's not a quotation mark at the end to tell PHP that you are done with the plain piece of text. Here is the same line twice, first with what you have and second with what it should be:
echo "The designer at Shirts 4 Mike shirts is named $fullName;
echo "The designer at Shirts 4 Mike shirts is named " . $fullName;
Does that help?
Once you get that line squared away, then you'll notice that you only need to echo out the $fullName variable once; right now, you have it in two separate lines. Here is the same line twice, first with what you have and second with what it should be:
echo $fullName . "!";
echo "!";
Of course, you don't need a separate echo statement for the exclamation point. I'd probably write all in one statement, like this:
echo "The designer at Shirts 4 Mike shirts is named " . $fullName . "!";
Does all that make sense?
Marco Roman
5,527 PointsWow! Thanks Randy...I kid you not that this was my original way of doing it:
echo "The designer at Shirts 4 Mike shirts is named " . $fullName . "!";
echo "The designer at Shirts 4 Mike shirts is named " . $fullName . "!";
The reason it wasn't working for me was because of the quotation mark spacing at the end of "named". I should have paid a closer look. I started messing with the code too much and got away from how I should be coding it. Thanks for all the help and for being so patient with e. You are a very good instructor.
Randy Hoyt
Treehouse Guest TeacherGlad you got it working! Hopefully working through all these iterations at least helped drive home or solidify the concepts you had already grasped.
I wish there was a way I could watch over people's shoulders when they took these code challenges and say, "Oh, you have an extra space there. Just take that out. No big deal." :~)
Marco Roman
5,527 PointsYou were very helpful and I understand the concept a little better now so thank you. It would have killed me if I didn't get this one before going to bed! I'll definitely be more careful with small things like that which can lead to long nights.
Matt Freeman
3,990 Pointsi type that code in and its still wrong arhhhh !!!!! frustrating !!!!
<?php
$firstName = "Mike"; $middleName = "the"; $lastName = "Frog"; $fullName = "$firstName ." ". $middleName ." ". $lastName";
echo "The designer at Shirts 4 Mike shirts is named" . $fullName . "!";
?>
Craig London
4,883 PointsMatt, you might want to try using an editor that has syntax highlighting. You will see you are not concatenating the string correctly, your quotes & periods are not in the right spots.