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

Stuck on concatenation. Code works on PHPFiddle but not in the PHP track exercise.

So, I am trying to do the task which gets the output "Rasmus Lerdorf was the original creator of PHP" with a new line break.

I put together the code below. When I run it in PHP Fiddle it works fine, yet when I create it in the actual exercise workspace, it tells me I'm not using the $fullname variable.

Any thoughts anyone. I've tried writing it a few different ways and it always returns the same issue. I can't see what's wrong.

<?php $firstName = "Rasmus"; $lastName = "Lerdorf"; $fullname = "$firstName" . " $lastName"; $output = $fullname . " was the original creator of PHP\n"; echo $output; ?>

2 Answers

Zachary Billingsley
Zachary Billingsley
6,187 Points

At a quick glance it looks ok, but I would clean up some of the concatenations. Not sure if it will work, but worth a try. Also $fullName might need a capital 'N'. The code challenges can be finicky....

$fullName = $firstName . " " . $lastName;

OR LIKE

$fullName = "$firstName $lastName";

Hope that helps!

Hi Zachary,

As you say, code challenges can be finicky. I first used "$fullName" based on all the previous video talk of using capitals on the second word. However, in the code challenge text they actually write it as "$fullname".....annoying huh! Tell me one thing, then do something different! This little baby took me almost 20mins to work out why it was saying I wasn't using the variable.

Anyways, "$fullname" is correct. Also, from your amended version of my code, I assumed it would be missing a space between the first and last name, but that's not the case at all so thanks :).

So I checked the final code again and thought to myself "what if I remove the $output variable step and just echo $fullname". Sure enough this works and I pass. So the correct code I needed was:

<?php $firstName = "Rasmus"; $lastName = "Lerdorf"; $fullname = "$firstName" . " $lastName"; echo $fullname . " was the original creator of PHP\n"; ?>

Thanks for your help Zachery :)