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 trialPeter Logan
751 PointsWhat's Wrong?
What am idoing wrong? The challenge is to put "Mike" (the name) on the screen.
<?php
$name = "Mike";
?>
<h1><?php echo "Mike" ?></h1>
2 Answers
Erik McClintock
45,783 PointsMeg,
They want you to echo the variable out in the same PHP block in this challenge, they don't want you to create h1 tags or a new PHP block.
Note: this challenge has failed students before for opening a second PHP block, hence the suggestion. Sometimes they can fail out for the oddest, smallest things.
Erik
Peter Logan
751 PointsOhhh, OK.
Craig Watson
27,930 PointsHi Meg,
Sorry, I didn't get your answer request till this morning, it looks like you have had the correct answer provided in one way or another already.
What Marcus has mentioned is correct you can use two PHP blocks to achieve what the code challenge is asking and it would be perfectly valid PHP.
However, if you had the need to execute this code on a live site as we all know we would take the option of using as little code as possible.
Sooo......
<?php
$name = "Mike";
echo $name;
?>
Again apologies for the delay :) Craig
Marcus Parsons
15,719 PointsIn a live site, you often wouldn't just echo out the name in the same code block. You would often get the name from a database query or from a cookie early on in the page and then use it somewhere in the body using up two different code blocks. Even though Meg's code doesn't pass the challenge, that is how this information would often be used. Thank you. Come again.
Marcus Parsons
15,719 PointsBtw, Craig, you're not simplifying your code block. You have too many spaces and extra lines and are therefore not using the simplest approach. So, nice try, but not quite. Let me help you out with that since you need it though:
<?php $name = "Mike"; echo $name; ?>
You guys need some lessons in simplicity it looks like.
Marcus Parsons
15,719 PointsWhen someone comes on to an answer and gives a correct, valid answer, you shouldn't do whatever you can to try to discredit that answer unless the answer is wrong which it is anything but. You will more often see variables created in one block and used in another in PHP. Again, you all need some practice with PHP before you figure this out, but that's okay.
Craig Watson
27,930 PointsVery sad really, I can assure you Meg not every question on treehouse is met with such a negative tone.
Marcus Parsons
15,719 PointsI had no negative tone whatsoever. If you interpret it that way, I feel sorry for you.
Marcus Parsons
15,719 PointsI am almost always positive in my responses except for when people who are still obviously new to a certain language come on to a question and try to discredit an answer I give for no reason. It wasn't that long ago that you were asking basic HTML and CSS questions.
Craig Watson
27,930 PointsThank you so much treehouse for the Unfollow Question button!!!!!
Shane Meikle
13,188 PointsShane Meikle
13,188 PointsAnd if I am not mistaken, they want the use of the variable instead of hardcoded.
so:
echo $name;
instead of
echo "Mike";
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsThey don't have to be in the same code block, but you are correct that there shouldn't be any elements in the page.
This is perfectly valid and will pass, as well:
Erik McClintock
45,783 PointsErik McClintock
45,783 PointsYes, Marcus Parsons, it looks like they have updated this challenge. Before, it was failing out for people when they had a second PHP block opened. Now it appears that is no longer the case, though you still don't need/want to open up a second block to echo this out.
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsBut you can and it is valid to do so ;)
Erik McClintock
45,783 PointsErik McClintock
45,783 PointsNot disagreeing that it is now valid for the challenge, I'm merely proposing better practices and simplicity!
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsI didn't say it was a best practice just that it was valid lol! Thanks. Come again.
Erik McClintock
45,783 PointsErik McClintock
45,783 PointsVery helpful. Thank you.
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsJust like it's helpful to tell people that they can't put code into a new code block. LOL. That's very helpful.