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

My code is rendering as it should be, but Im still getting an error.

So Task 3 is working fine,but in task 4, im changing the variable and for some reason that is causing "Task 3" to stop working.

<?php 

$flavor = "Cookie Dough";

echo "Your favorite flavor of ice cream is "; echo "$flavor"; echo ".";

 if ($flavor == "Cookie Dough") { 

echo "Randy's favorite flavor is cookie dough, also!"; 

} 

?>
<?php

 $flavor = "Cookie Dough"; 

echo "Your favorite flavor of ice cream is "; 

echo "$flavor";

echo "."; 

if ($flavor == "Cookie Dough") { 

echo "Randy's favorite flavor is cookie dough, also!";

 } 

?>

4 Answers

Louis Otto
Louis Otto
23,264 Points

can you please post your code so we can take a look?

Hey Louis, here: <?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>"; } ?>

Louis Otto
Louis Otto
23,264 Points

OK you've removed some of the <p> tags which are essential, but otherwise it's perfect. Remember also that it asks you to check what happens when it doesn't match, so change your flavor to chocolate as I've done, and the below will pass. I hope this makes sense:

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

Sorry about the double post, the code I commented above is your code so that anyone trying to help can view it all easily.

I believe task one, two, and three concatenated some <p> tags into the echo commands. If you removed those, that could be your problem. In that case, your code as it functions is not the problem.

Louis Otto
Louis Otto
23,264 Points

Also you wrapped the variable $flavor in quotes, you don't do that for variables, only strings.