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 trialMaxwell Lees
Courses Plus Student 1,001 PointsWhy is This Wrong?
The Output is correct and i did the logic correct maybe I didn't do it in the way the computer Wanted I set the Variable to "Rasmus" Which is what it wanted but it said it was wrong my code isn't incorrect from what I can Tell.
<?php
$firstName = "Rasmus";
$lastName = " Lerdorf";
$fullName = ($firstName .= $lastName);
echo($fullName);
?>
Maxwell Lees
Courses Plus Student 1,001 PointsHow do you post the image i don't see where i can
KRIS NIKOLAISEN
54,971 PointsImages are hard to work with. It is better to copy and paste your code and format it using markdown (see the cheatsheet at the bottom of this page)
Maxwell Lees
Courses Plus Student 1,001 PointsOk figured it out
Maxwell Lees
Courses Plus Student 1,001 PointsI figured out how to post the code not the question itself just to specify
KRIS NIKOLAISEN
54,971 PointsI stand corrected
3 Answers
Steven Parker
231,198 PointsI see three issues that would affect the challenge but would not be seen by looking only at $fullName:
- there is a stray space at the beginning of the string
" Lerdorf"
- the "
.=
" operator modifies $firstName, but the challenge is expecting it to remain as it was ("Rasmus") - you'll need to add a space between the combined names without changing the individual names
Maxwell Lees
Courses Plus Student 1,001 PointsYeah You are Right I changed it to
$fullName = ("$firstName $lastName\n");
worked just fine that way
Steven Parker
231,198 PointsGood job! I don't think the newline ("\n") was part of the instructions but it was nice that it allowed it. But in general you'll get best results with the challenges if you do only what the instructions ask for. "Extras" can confuse the validation!
Happy coding!
KRIS NIKOLAISEN
54,971 PointsThe bummer message isn't very helpful. But one reason the challenge will fail is you have a space before Lerdorf in your lastName variable. Instead of a space there you can add one with concatenation to fullName as follows:
$fullName = $firstName . ' ' . $lastName;
Maxwell Lees
Courses Plus Student 1,001 PointsIn php whitespace doesn't matter so the space before that word is not the issue I am Having the issue is that it is saying that my variable $firstName is not equal to "Rasmus" which it clearly is.
Steven Parker
231,198 PointsThe ".=
" alters $firstName, try echoing it out instead of (or along with) $lastName and see for yourself.
And whitespace might not matter in code, but it does matter inside strings.
KRIS NIKOLAISEN
54,971 PointsIgnore the error message about the firstName. That is why I said the bummer message isn't very helpful.
Steven Parker
231,198 PointsThe fact that $firstName gets changed and is no longer equal to "Rasmus" is quite pertinent!
KRIS NIKOLAISEN
54,971 PointsKRIS NIKOLAISEN
54,971 PointsCan you post your code?