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 trialFabrizio Rinaldi
5,359 PointsVariables and Conditionals
Task:
Change the value in the flavor variable to cookie dough. Preview the code and make sure the message appears.
Answer.
<?php $flavor = "chocolate";
echo "<p>Your favorite flavor of ice cream is "; echo $flavor; echo ".</p>"; $flavor = "cookie dough"; if ($flavor== "cookie dough") { echo "Randy's favorite flavor is <?php $flavour; ?> also!</p>"; }
Can't understand what i've to change, and shows me an error.
Thanks for your help =)
2 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Fabrizio Ony thing i can see is you have not closed your php tags and second not sure why you have to open and close another php tag to echo $flavor in the if block.Try the below.
<?php $flavor = "chocolate"; echo "Your favorite flavor of ice cream is ".$flavor; $flavor = "cookie dough"; if ($flavor== "cookie dough") { echo "Randy's favorite flavor is ".$flavour." also!"; } ?>
Jason Anello
Courses Plus Student 94,610 PointsHi Fabrizio,
You don't want to change Randy's statement it just needs to be wrapped in the if
statement. In your code it looks like you're opening another php block inside of another php block.
<?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>";
}
?>