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 trialMUZ140067 Precious Mutangi
13,064 PointsSTAGE 2 CHALLENGE TASK 3 OF 4
The message in the final echo command only makes sense if your favorite flavor is the same as mine. Add a conditional around that final echo command that checks if the flavor variable has a value of "cookie dough." (Remember to choose carefully between using a single equal sign and a double equal sign in the check.) Preview the code and, if you have a different flavor, make sure the message disappears.
<?php
$flavor = "vanilla";
echo "$flavor";
if ($flavor == "cookie dough");
echo "<p>Your favorite flavor of ice cream is ";
echo "vanilla";
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
2 Answers
Greg Kaleka
39,021 PointsHi there!
You might want to take another look at the video (often, this is a good thing to do if a code challenge is stumping you) to see how to write if statements in PHP. Here's the solution, but make sure you really understand it before moving on. You may also want to have a look at the PHP documentation for if statements.
<?php
$flavor = "vanilla";
echo "$flavor";
echo "<p>Your favorite flavor of ice cream is ";
echo "vanilla";
echo ".</p>";
if ($flavor == "cookie dough") {
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
}
?>
Erik McClintock
45,783 PointsYou're not writing your if statement correctly. You currently have a semi-colon after the condition, which is ending the line, and your if statement thus isn't doing anything. If you recall from your lessons, after your conditional, you need to open up a set of curly braces to put code inside, so that IF the condition evaluates to true, that code will run, otherwise, it will not. You are also not replacing the hard coded "vanilla" string with the value of your variable ($flavor), and you are not writing the conditional in the correct place based on the instructions given: the task tells you to wrap the final echo command in your if statement.
You may benefit more from going back and rewatching some videos to really cement the syntax of these different aspects of the language in your head. It is absolutely paramount that you memorize how these look and work, or you will never truly understand the language or be able to write your own code.
Erik