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
STAFF
Jennifer Nordell
Treehouse Staff

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!