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 Build a Simple PHP Application Adding a Contact Form Concatentation

Simple concatenation php issue, I can't spot where my code is wrong.

Create a variable called fullName and assign it a value equal to the concatenation of the firstName variable, a space, the middleName variable, a space, and the lastName variable.

<?php

$firstName = "Mike";
$middleName = "the";
$lastName = "Frog";
$fullName = $firstName." ".
$middleName." ".
$lastName;

echo "The designer at Shirts 4 Mike shirts is named $fullName";

?>

Are you sure that code is not passing?

I copied your code block and pasted it into the challenge and it passes all the way up through task 3.

Hi Guys,

That was my first issue / bug on treehouse and the feedback was awesome.

  • I went through the code challenge again and the exact same code worked.

It could have been an issue with the refresh button or caching of the page. I don't honestly know why it didn't pass that's why I was asking.

Thanks for the feedback on this challenge, helped me understand some of the rules a bit better.

2 Answers

Hey Dillion,

It's a very simple mistake. You're suppose to declare and concatenate the $fullName variable outside of the string.

<?php

$firstName = "Mike";
$middleName = "the";
$lastName = "Frog";
$fullName = $firstName." ".$middleName." ".$lastName;


echo "The designer at Shirts 4 Mike shirts is named ".$fullName;

?>

David,

Actually, regardless of what the challenge may call for, his version of the echo statement is actually syntactically correct. When you use double-quotes on a string, any variable that is called within will have its value displayed. Single-quotes, on the other hand, will display the name of the variable and not the value. If that is what's making Dillon's challenge failing, I'd advise you to fix the challenge as it gives people new to the language false information and speculation.

Cheers!

I'm only just a moderator, so i'm just helping anyone with challenges that I may have passed already. I wasn't the one who created the challenge. I'm here to learn just like everyone else who is a Treehouse member. Any bugs should be reported directly to Treehouse. Thanks for the info Dillion.

Shawn,

I've verified that it does pass with double quotes and variables inside.

I'd tend to agree with you that it should pass both ways, dillon's or David's, if the instructions said to produce a certain output with no requirements on how you do it. However, the instructions specifically say to concatenate the name to the end of the string. So I kind of feel like it shouldn't pass for not following the requirements.

When you use a variable inside a double quoted string, that's not considered concatenation is it?