PHP Build a Basic PHP Website Adding a Basic Form Concatenation

Thomas Barkel
PRO
Thomas Barkel
Pro Student 7,222 Points

concatenating variables

I'm unsure why i'm being told in the quiz that $fullName is not properly concatenated. Can someone advise?

index.php
<?php

$title = "Dr.";
$firstName = "David";
$lastName = "Bowman";
$fullName .= $title . $firstName . $lastName;



echo "The lead character from 2001: A Space Odyssey is named ____";

?>

3 Answers

Steven Parker
Steven Parker
171,345 Points

The error message contained a hint: "Bummer: Make sure $fullName is set to the concatenation of $title, $firstName, and $lastName, with spaces in between."

You're joining all the words, but you still need a couple of spaces to keep them all from running together. Also the assignment should be just a plain "=" (not ".=").

Thomas Barkel
PRO
Thomas Barkel
Pro Student 7,222 Points

how are the spaces that are between the periods insufficient for creating "spaces in between"?

Steven Parker
Steven Parker
171,345 Points

Those don't get added into the string. To get spaces into the string, they need to be literal strings (made by surrounding each space in quotes). Those can then be concatenated with extra periods. Example:

<?php
$bothWords = $firstWord . " " . $nextWord;
Amber Stevens
STAFF
Amber Stevens
Treehouse Staff

If you hit the 'Preview' button on the code challenge you'll see what it looks like and I think you'll be able to better see what the problem is