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 trialGary Taylor
1,696 PointsHaving trouble adding space to the string.
I have reviewed the videos and did some searching online and cannot find how to add these two strings together and add space. What am I missing?
<?php
//Place your code below this comment
$firstName = 'Rasmus';
$lastName = 'Lerdorf';
$fullName = "$firstName" + "$lastName";
?>
1 Answer
Justin Radcliffe
18,987 PointsTry using PHP concatination like this:
$fullName = $firstName . ' ' . $lastName;
This:
. ' ' .
concatinates the two variables and adds one space character to the string.
Gary Taylor
1,696 PointsGary Taylor
1,696 PointsIt is still giving me an error and saying I did not add a space between first and last name. This course is frustrating because the code challenges often cover material not referenced in the videos.
Justin Radcliffe
18,987 PointsJustin Radcliffe
18,987 PointsLooking at your original code, do this:
$fullName = $firstName + $lastName;
$fullName = $firstName $lastName;
$fullName = $firstName . '' . $lastName;
$fullName = $firstName . ' ' . $lastName;
When I run this last code snippet in the challenge is passes.Gary Taylor
1,696 PointsGary Taylor
1,696 PointsGoing through it again it passed. I appreciate your help.