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

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,884 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.