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

Baur Alzhanov
Baur Alzhanov
7,028 Points

Error. I can't check my work.

<?php $flavor = "ice", "cream", "rock road"; if ($flavor == "ice"){ } else if ($flavor == "cream"){ } echo $flavor; echo "<p>Your favorite flavor of ice cream is "; echo "vanilla"; echo ".</p>"; echo "<p>Hal's favorite flavor is cookie dough, also!</p>";

?> final exercise. first I don't understood what I need to do. Second Work couldn't cheek my work.

index.php
<?php
$flavor = "ice", "cream", "rock road";
if ($flavor == "ice"){
} else if ($flavor == "cream"){
} 
echo $flavor;
echo "<p>Your favorite flavor of ice cream is ";
echo "vanilla";
echo ".</p>";
echo "<p>Hal's favorite flavor is cookie dough, also!</p>";

?>

2 Answers

Gianmarco Mazzoran
Gianmarco Mazzoran
22,052 Points

Hi Baur,

it's me again! In the final stage of this challenge you need to compare the value inside your flavor variable with this value "cookie dough". This time you are very close:

  • you have only to put the if statement after the closing p tag and pass in the last echo statement.
  • since you have a string variable is not possible to pass multiple values separate with a colon. If you want to store multiple variable you need an array but it's not this case.

So if the two flavor match, it would be print "Hal's favorite flavor is cookie dough, also!" else anything would be printed!

<?php
$flavor = "cream";
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 it helps to understand the "if" statement!

Baur Alzhanov
Baur Alzhanov
7,028 Points

Thanks a lot, Gianmarco! I understood my snag.

Gianmarco Mazzoran
Gianmarco Mazzoran
22,052 Points

This is the important Baur! Happy coding! :)