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

PHP

Code Challenge: Concatentation

HELP!

here is my sample of code Where am I going Wrong?

<?php

$firstName = "Mike";
$middleName = "the";
$lastName = "Frog";
$fullName = "";
$fullName = $fullName .$fistName ."\n";
$fullName = $fullName .$middleName ."\n";
$fullName = $fullName .$lastName ;

echo "The designer at Shirts 4 Mike shirts is named $fullName";
?>

6 Answers

The output of your code is:

The designer at Shirts 4 Mike shirts is named the Frog

It's hard to tell what you are trying to achieve because you don't specify the lesson/code challenge you are stuck on.

these code challenges are weird i can see multiple problems with this code. but im guessing the last bit is where it says you've got stuck. The echo should be

echo "The designer at Shirt 4 Mike shirts is named" . $fullname;

which would print: The designer at Shirt 4 Mike shirts is named Mike <br/> the <br/> Frog

In future. $firstName="Mike"; $middleName="the"; $lastName="Frog"; $fullName=$firstName." ".$middleName." ".$lastName;

Then echoing $fullName ->will give-> Mike the Frog

To educate you: concatenation is using the . character to attach strings together. $variable=$variable . $variable; $variable="hello"."jason"."thankyou".$variable; echo "".$variable; echo "myname is ".$variable . " and I like ". $variable;

and its white space independent.

hope that makes sense

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

(1) You are missing an r in one of your variables. You have fistName instead of firstName.
(2) The "\n" creates a line break, not a space. You want you put this " " instead to make a regular space.

I think addressing those two things will fix it.

I'm not sure if i get the logic as to why the $fullName variable needs to be assigned a blank value, then have other values added (concatenated) sequentially. Why is it not possible to have something like the below?

$fullName = $firstName . "  " . $middleName . "  " . $lastName;
Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

@Andy, That works perfectly fine! (That's probably how I would do it in a real project.)