PHP Build a Basic PHP Website (2018) Building a Media Library in PHP Variables and Conditionals

Andrew Lenti
Andrew Lenti
Front End Web Development Techdegree Student 7,193 Points

unsuccessful if statement (question #3)

Hello. Firstly upon trying to answer the third (and last question) in the last section of 'Build a Basic PHP Website, I continuously get 'kicked out' with a strange error message and am forced to start from the beginning. This issue was present yesterday as well as today. The problem which I cannot seem to resolve (and perhaps this is why the issue is persisting) regards the if statement with the cookie dough ice cream. I am trying to create an if statement that states if the variable $flavor is equal to 'cookie dough' then include the statement 'Hal's favourite flavor is also cookie dough' I am stuck on this one.. My code is as follows.. Please help for I would like to go ahead with my studies but am blocked here for two days now.

<?php $flavor = "pistacchio"; ?>

<p>Your favorite flavor of ice cream is <?php echo $flavor ?>.</p>

if ( $flavor == "cookie dough" {

<p>Hal's favorite flavor is <?php echo $flavor ?>, also!</p>

}

index.php
<?php

echo "<p>Your favorite flavor of ice cream is ";
echo "vanilla";
echo ".</p>";
echo "<p>Hal's favorite flavor is cookie dough, also!</p>";

?>

1 Answer

cm21
cm21
150,624 Points

Hi Andrew,

Looks like your if statement is missing a closing parenthesis. Also, you'll want to be sure to echo, because it's needed to output the string for the user to be able to read it.

<?php
$flavor = "pistacchio";
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>";
};
?>

Hope this helps!