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

General Discussion

code-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
James Barnett
39,199 Points

You 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.

Here's my new code, what is wrong with it??

$fullName = $firstname . $middleName . $lastName; It hs spaces between them

James Barnett
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.

I 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
samiff
31,206 Points

James 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.

code removed

kobi arami

James Barnett
James Barnett
39,199 Points

I'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.

right,i am sorry for that. thank you.

Konrad Pilch
Konrad Pilch
2,435 Points

Hi. 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.

I 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
James Barnett
39,199 Points

I see two issues here:

  1. Concanentate the spaces like I did in my example.
  2. 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.

Hey James, I was able to get it to pass by adding the . " " . between each variable in the string.

Thanks for your help.

Ian

yeah 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;

?>

Hey John, Double check your spelling of $firstName. Hope that helps! -Jessica

This 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 ";

?>
GURJAP SINGH
GURJAP SINGH
7,556 Points

This 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 />";

Just a tip for anyone experiencing problems with the second step.

He doesn't take single quotes.

<?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

$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.

This 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
Cheng Shan Cheng
6,422 Points

your put $title in wrong order