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

Kari Jones
Kari Jones
6,217 Points

Code Challenge Help!

I got to this step on the last Code Challenge for Creating the Menu and Footer in Build a Simple PHP Application. I know I have two other forum posts about code challenges, but that just shows how bad I am at this. Here is my code:

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

Please Help!

5 Answers

Chase Lee
Chase Lee
29,275 Points

I don't know what code challenge you're on but if I'm right your conditional should have the variable $flavor and check if it is Randy's flavor.

Hope that helps.

Kari Jones
Kari Jones
6,217 Points

I am on the last code challenge in Creating the Menu and Footer badge, inside of Build a Simple PHP Application in the Programming course from the library. I posted the wrong code at the end there. Here is what I actually have:

<?php
$flavor = "Coffee";
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor;
echo ".</p>";
<?php if ($flavor  == "cookie dough") { echo "<p>Randy's favorite flavor is cookie dough, also!</p>"; } ?>
?>
Chase Lee
Chase Lee
29,275 Points

It looks like you have too many closing PHP tags.

Chase Lee
Chase Lee
29,275 Points

Oh never mind that but you should take you opening and closing PHP tags on the sixth line.

Waqar Mohammad
seal-mask
.a{fill-rule:evenodd;}techdegree
Waqar Mohammad
iOS Development Techdegree Student 9,914 Points

<?php $flavor = "Coffee"; 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>"; } ?>

This should work - you had an opening php tag just before the 'if' statement which wasn't required.

Kari Jones
Kari Jones
6,217 Points

Thank you! That fixed it!