Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!