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

Ross Campbell
Ross Campbell
5,410 Points

TASK - 3 of 4 what am i doing wrong?

Hey guys, sorry to ask, i've rematched the video a few times now and can't quite work out what i'm doing wrong in my coding.

this is what is got.

<?php

$flavor = "raspberry";

echo "<p>Your favorite flavor of ice cream is ";
if ( $flavor == raspberry )   echo "raspberry" ;
echo ".</p>";
?>
<?php
if ( $flavor == cookie dough ) echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
Ross Campbell
Ross Campbell
5,410 Points

Thank you so much everyone for your quick responses!

Really really helpful, and thanks for picking me up on the misuse of the variable in the 2nd TASK - too!

regards

ross

2 Answers

Strings must be wrapped inside double quotes. So your code would have to be like this:

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

In your code, you wrote: if ( $flavor == raspberry ) echo "raspberry" ;. While this code is syntactically flawless, it's not the best approach.

What you have done here is declaring your favorite flavor with $flavor = "raspberry". Then you make an unnecessary check if your favorite flavor is "raspberry" before printing it out. The variable $flavor is already meant to contain your favorite flavor, so no need to check for this.

So all you need to do here is to echo the variable flavor as shown in my example above.

Good luck!

Hi Ross,

For task 2 you only need to echo the flavor variable. echo $flavor; You don't need an if condition for that.

Then for task 3 you're missing the quotes around "cookie dough" since it's a string.

Also, you don't have to close and then open a new php block. It can all be in 1 php block.