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 Creating the Menu and Footer Variables and Conditionals

Conditional Can't Be True and False Simultaneously

So the third task in this exercise is to set up a variable that differs from the variable that the conditional is looking for. Basically, set things up so the conditional is not met. In the fourth step, the instructions are to change the value of the variable so the conditional IS met and the message appears. I did as instructed, and the preview showed that the conditional message was appearing. However, every time i change the value to match the conditional, i get an error message that says "Step 3 is no longer passing" Which makes sense, because the objective of step three was to make sure the conditional DID NOT pass. I don't want to jump to faulting the system, but I feel like I'm being asked to do two things simultaneously. Step three requires that the conditional not pass, and step four requires that it does pass. If I pass the conditional, step three stops passing. If I don't pass the conditional, I can't get past step four. Is there something that I'm not understanding about this conditional question?

index.php
<?php

$flavor = "cookie dough";
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor;
echo ".</p>";
if($flavor == "cookie dough") { echo "<p>Randy's 
favorite flavor is cookie dough, also!</p>"; };

?>

Joshua,

Believe it or not your error doesn't stem from a problem with your conditional statement, but it's actually a PHP syntax error. You have a new line between Randy's and favorite. Put the ECHO statement on the same line and the code challenge will work. Also, since you are only doing one thing inside of the IF statement, you do not need the curly braces. Remove the curly braces and put the echo statement on a new line underneath the IF statement (make sure you indent) and the code challenge should pass.

Cheers!

Shawn is absolutely correct about this challenge. But in your real PHP code, you can have multi-line echo statements such as what you put. This is perfectly valid in PHP (and from an old article a friend had posted on a gaming site I had created):

echo "
<h1>New System?</h1>
<p>Is it already time for a new generation of consoles to come out? Nintendo has announced that they will be releasing
the Wii U sometime next year. Does this mean Sony and Microsoft have something in the works too?</p>
<p>Sony claims that they have no intention of releasing a new system anytime soon. They say that the PS3 is only halfway through its expected 
lifespan, claiming that they have games out now that have yet to push the system to its full potential. However, will they keep this 
stance if Microsoft releases a new system? Does Microsoft have any plans on doing this?</p>
<p>They have yet to announce anything about a new system, but my theory is: Nintendo is releasing a new, more powerful system, in order to compete with Sony
and Microsoft since they now have their own versions of motion controllers. It will probably be a few more years before
we see a new generation of systems from Sony or Microsoft. -Jonathan Kade</p>";

Marcus

You are correct. I was writing my response late at night and I didn't mean a PHP syntax error more talking about the code challenge's syntax error. While multiline echo statements are proper syntax, I try to stay away from it most times as there are other ways to do it like escaping out of PHP.

Cheers!

Indeed, Shawn! It's even better practice to escape out of PHP than to use those long echo statements. When I was first learning PHP, I used to do huge echo statements, and although I didn't notice any load time difference, someone with a slower connection might I suppose. I still revert back to that sometimes, but I'm trying to break myself of that haha.