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 trialTom Farmer
506 Pointscode-challenge : Concatenating
<?php
$firstName = "Mike"; $middleName = "the"; $lastName = "Frog"; $fullName = $firstName . $middleName . $lastName; echo "The designer at Shirts 4 Mike shirts is named ____";
?> I honestly dont understand what is wrong with it this time?
15 Answers
James Barnett
39,199 PointsYou didn't specify which step you are on, so I'm guessing you are on Step 2.
The instructions for that step are:
Create 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.
You forgot to include the spaces in your concatenation.
Tom Farmer
506 PointsHere's my new code, what is wrong with it??
$fullName = $firstname . $middleName . $lastName; It hs spaces between them
James Barnett
39,199 Points@Tom -
The instructions are referring to echo'ing out a literal space character as a string.
I created a working demo so you can see what I mean.
Ian Warner
5,563 PointsI looked at your working demo but I still can't get it to pass the Code Challenge Concatenation. Here's my code:
<?php
$firstName = "Mike";
$middleName = "the";
$lastName = "Frog";
$fullName = $firstName . $middleName . $lastName;
echo "<br /> <br />";
echo "The designer at Shirts 4 Mike shirts is ____";
?>
Any help would be much appreciated! Thanks, Ian
samiff
31,206 PointsJames is correct, you want to see "Mike the Frog" output in the preview, and the way you have it would output "MiketheFrog". You simply need to add some empty spaces in your concatenation.
kobi arami
Courses Plus Student 2,645 Pointscode removed
kobi arami
James Barnett
39,199 PointsI've removed your code, we generally don't favor giving away answers.
Suggesting a fellow Treehouse user cut & paste your answer doesn't do them any favors in the long run as they still don't understand the concepts presented in the lesson.
kobi arami
Courses Plus Student 2,645 Pointsright,i am sorry for that. thank you.
Konrad Pilch
2,435 PointsHi. James, in a way I agree with you and disagree. Coping and pasting into the code challenge will not give any help yes but, the person might not even finish that coz he/she might get annoyed with it etc.. I would analise the code and learn it that way i wont have to waste time? or maybe use it ? depending if somebody is looking for answer to just putting in it anything .
So having a code and analizing it and then using it , will teach the student .
Thats my opinion.
Carl Taggett
10,321 PointsGot it!
Ian Warner
5,563 PointsI looked at James' working demo but I still can't get it to pass the Code Challenge Concatenation. Here's my code:
<?php
$firstName = "Mike";
$middleName = "the";
$lastName = "Frog";
$fullName = $firstName . $middleName . $lastName;
echo "<br /> <br />";
echo "The designer at Shirts 4 Mike shirts is ____";
?>
Any help would be much appreciated. Thanks, Ian
James Barnett
39,199 PointsI see two issues here:
- Concanentate the spaces like I did in my example.
- The purpose of concanentating variables with a string is to put a value of a variable in the string dynamically and not have to hard code it.
If this doesn't make sense then I'm going to take another tactic and ask you how concanentating works with 2 (or more) variables and why would want to concanentate a string and a variable together.
Ian Warner
5,563 PointsHey James, I was able to get it to pass by adding the . " " . between each variable in the string.
Thanks for your help.
Ian
John Weland
42,478 Pointsyeah I am still having trouble, here's what I have.
<?php
$firstName = "Mike";
$middleName = "the";
$lastName = "Frog";
$fullName = $firtName . " " . $middleName . " " . $lastName;
echo "<br /> <br />";
echo "The designer at Shirts 4 Mike shirts is named" . $fullName;
?>
Jessica Buchanan
2,913 PointsHey John, Double check your spelling of $firstName. Hope that helps! -Jessica
Ariel Beninca
6,390 PointsThis is correct. You just need to give it spaces buy putting it in "" with a space at the end.
<?php
$firstName = "Mike";
$middleName = "the";
$lastName = "Frog";
$fullName = "$firstName " . "$middleName " . "$lastName";
echo "The designer at Shirts 4 Mike shirts is named $fullName ";
?>
Raymundo Figueroa
Front End Web Development Techdegree Student 25,606 PointsTHX, ARIEL FOR THE CORRECTION OF THE CHALLENGE.
GURJAP SINGH
7,556 PointsThis is the answer for step 2 (i may be bit late though, lol):
$firstName = "Mike"; $middleName = "the"; $lastName = "Frog";
$fullName = $firstName . " " . $middleName . " " .$lastName; echo "<br /> <br />";
Erik van Dam
317 PointsJust a tip for anyone experiencing problems with the second step.
He doesn't take single quotes.
MUZ140306 Blessing Muhakichi
1,627 Points<?php
$firstName = "Mike"; $middleName = "the"; $lastName = "Frog"; $fullName = $firstName."".$middleName."".$lastName;
echo "The designer at Shirts 4 Mike shirts is named ____";
?> Wats wrong with this one, im stuck
Cesar De La Vega
13,900 Points$fullName = "$firstName " . "$middleName " . "$lastName";
the . concatenates. The BLANK SPACE at the END of EACH variable AND before the closing " adds a BLANK space after each variable.
Ryan Moody
20,499 PointsThis code isnt working for the second challenge. What is wrong with it? <?php
$title = "Dr."; $firstName = "David"; $lastName = "Bowman";
$fullName = $firtName . " " . $title . " " . $lastName;
echo "The lead character from 2001: A Space Odyssey is named ____";
?>
Cheng Shan Cheng
6,422 Pointsyour put $title in wrong order