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