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 Basic PHP Website (2018) Building a Media Library in PHP Variables and Conditionals

brolyen
brolyen
4,605 Points

I'm not sure on how to proceed on this one, can you show me the solution?

I don't get the objective of this exercise. English is not my native language. Any help is appreciated.

index.php
<?php
$flavor = "vanilla";

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

?>

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You're doing great! You got 2 out of 3 right, and that's not bad at all. This is what it wants. Hal's favorite flavor is cookie dough. You stored your favorite flavor in $flavor. If your favorite flavor happens to also be cookie dough, then that last line should appear saying that Hal's favorite flavor is also cookie dough. Otherwise, that last line won't appear at all. Really the biggest difference between my code and yours is that mine has the if statement on the outside of the last echo. Take a look at my solution and see if it makes sense.

<?php
$flavor = "vanilla";

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

?>

Here we set up our favorite flavor as vanilla. It echos out our favorite flavor. So far so good. Now if our favorite flavor happens to be cookie dough, it will print out that Hal's favorite flavor is cookie dough also. Otherwise, that last echo never happens. Hope this helps! :sparkles:

brolyen
brolyen
4,605 Points

Thank you very much!