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 trialMarcuz Gabriel Larsen
Full Stack JavaScript Techdegree Graduate 16,462 PointsCreate a variable called $fullName and assign it a value equal to the concatenation of the $title variable, a space, the
What have I done wrong???
<?php
$title = "Dr.";
$firstName = "David";
$lastName = "Bowman";
$fullName = "Dr. " . $title . "David " . $firstName . "Bowman" . $lastName;
echo "The lead character from 2001: A Space Odyssey is named ____";
?>
Marcuz Gabriel Larsen
Full Stack JavaScript Techdegree Graduate 16,462 PointsThank you David for a quick reply! Unfortunately still a challenge!
<?php
$title = "Dr."; $firstName = "David"; $lastName = "Bowman";
$fullName = "$title " . "$firstName " . "$lastName "; echo $fullName;
echo "The lead character from 2001: A Space Odyssey is named ____";
?>
The preview shows correct but I get the message:
Bummer! Make sure $fullName is set to the concatenation of $title, $firstName, and $lastName, with spaces in between.
2 Answers
Carlos Federico Puebla Larregle
21,074 PointsYou could solve the task like this:
<?php
$title = "Dr.";
$firstName = "David";
$lastName = "Bowman";
$fullName = $title . " " . $firstName . " " . $lastName;
echo "The lead character from 2001: A Space Odyssey is named ____";
?>
We are assigning the variable $title a white space (" "), the variable $firstName another white space (" ") and finally the variable $lastName. All that using . (dots) to concatenate. I hope that helps a little bit.
Marcuz Gabriel Larsen
Full Stack JavaScript Techdegree Graduate 16,462 PointsThat worked thank you Carlos.
For the one who has the same challenge remember not to add a space after $lastName - even though it looks weird and is connected to the echo without a space: "Dr. David BowmanThe lead character from 2001: A space Odyssey is Named ___";
David Bath
25,940 PointsWhen you use variables, don't put them inside quotes. Take a look at how Carlos did it.
David Bath
25,940 PointsDavid Bath
25,940 PointsI think if you echo out $fullName you will see what you are doing wrong. You are actually concatenating each variable to its text equivalent, so "Dr. Dr." etc. You just need to concatenate the variables (with added spaces).