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 trial

PHP PHP Basics Daily Exercise Program String Manipulation

Why 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);
?>

Can you post your code?

How do you post the image i don't see where i can

Images 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)

Ok figured it out

I figured out how to post the code not the question itself just to specify

I stand corrected

3 Answers

Steven Parker
Steven Parker
231,261 Points

I 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

Yeah You are Right I changed it to

$fullName = ("$firstName $lastName\n");

worked just fine that way

Steven Parker
Steven Parker
231,261 Points

Good job! :+1: 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!

The 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;

In 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
Steven Parker
231,261 Points

The ".=" 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.

Ignore the error message about the firstName. That is why I said the bummer message isn't very helpful.

Steven Parker
Steven Parker
231,261 Points

The fact that $firstName gets changed and is no longer equal to "Rasmus" is quite pertinent!