Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

abdul faiz mohd jayramie eng
PLUS
abdul faiz mohd jayramie eng
Courses Plus Student 4,478 Points

PHP forms..........1 hour past by without solution

Hmm....i wonder what was the error.

Question Was: "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."

My Final Answer:

<?php

$firstName = "Mike";

$middleName = "the";

$lastName = "Frog";

$fullName = $firstName ."\n";

$fullName = $fullName . $middleName ."\n";

$fullName = $fullName . $lastName;

echo $fullName;

echo "The designer at Shirts 4 Mike shirts is named ____";

?>

I tested in the preview, it does appear to be "Mike the Frog" with a space in between. What was the error?

i also tried these method:

$fullName = $firstName . $middleName . $lastName;

also tried adding "\n" in between. all method fail.

4 Answers

Mike Croft
Mike Croft
7,463 Points

$fullName = $firstName . " " . $middleName . " " . $lastName;

This should work, you need to add the spaces as you can see above, hope this helps

abdul faiz mohd jayramie eng
PLUS
abdul faiz mohd jayramie eng
Courses Plus Student 4,478 Points

i did tried that solution. i was not aware that space between them was sensitive case. the spaces for . " " . in the tutorial video was not so obvious. hope they'll fix this. Thanks btw. Merry Christmas!

Mark Flavin
Mark Flavin
10,199 Points

Not to further confuse matters but as long as you use double quotes ("") you can actually make the code a bit cleaner.

$fullName = "$firstName $middleName $lastName";

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

It looks like the code you originally posted was all correct except for the "\n"; you just needed to replace each "\n" with a " ". The "\n" creates a line break (instead of a space), so your PHP variable actually had a value like this:

Mike
the
Frog

You are right that the preview is confusing! In the preview, it actually looked correct because the browser ignores the line breaks and displays it as a space. I think I'll modify the code challenge to display a more helpful message in that case.