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

I'm getting an error on the quiz - "looks like Task 1 is no longer passing" - what is causing this?

I'm pretty sure I have the code correct, but it seems like it's not assigning the variable? Note: everything works up to step three, but I cannot preview. I't just a blank screen.

index.php
<?php
$flavor = "Rocky Road";

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

?>

2 Answers

Antonio De Rose
Antonio De Rose
20,879 Points
<?php
$flavor = "Rocky Road";

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

#the issue is in the last line, when you have passed the double quotes within double quotes.
#engine now thinks, the moment, you have passed the double quote, that is the end of the statement.
#and don't know what to do with the remainder, and throws an error.
#there are 2 ways get around this issue

# 1) is to surround the inner double quotes with single quotes, and take the inner double quotes completely out
echo "<p>Hal's favorite flavor is <?php if ($flavor == 'Rocky Road') { echo 'Rocky Road'; } ?>, also!</p>";


# 2) is to have the double quotes just as you have put it right now, but escape
#the double quote, by having a backslash "\", in front of the inner double quote
#this way, you are telling the php interpreter, ignore the preceding character
#after the backslash
echo "<p>Hal's favorite flavor is <?php if ($flavor == \"Rocky Road\") { echo \"Rocky Road\"; } ?>, also!</p>";



?>

Oh that makes sense. Thanks very much for the clarification.