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

What is the problem with this script, it's asking to echo in $flavor. I do not assume any mistakes but it showing Bummer

The message in the final echo command only makes sense if your favorite flavor is the same as Hal's. Add a conditional around that final echo command that checks if the flavor variable has a value of "cookie dough." (Remember to choose carefully between using a single equal sign and a double equal sign in the check.) Preview the code and, if you have a different flavor, make sure the message disappears.

index.php
<?php
$flavor = "Chocolate";
echo "<p>Your favorite flavor of ice cream is ";
echo .$flavor;
echo ".</p>";
if($flavor == "cookie dough") {
echo "<p>Hal's favorite flavor is also cookie dough, also!</p>";
} else {
echo "<p>Too bad Hal doesn't love $flavor like I do!</p>";
}

?>
Julian Kennon
Julian Kennon
21,825 Points

This is your problem...

<?php
  echo .$flavor;

Use the . to combine strings within one statement, for example...

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

which would work. However, if you want to use multiple lines, it would be...

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

The problem still persists, as it saying : Bummer! We tried setting $flavor to "cookie dough", but we didn't see the message "Hal's favorite flavor is cookie dough, also!".

<?php
$flavor = "Chocolate";
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor;
echo "</p>";
if($flavor == "cookie dough") {
echo "<p>Hal's favorite flavor is also cookie dough, also!</p>";
} else {
echo "<p>Too bad Hal doesn't love $flavor like I do!</p>";
}

?>
Joel Bardsley
Joel Bardsley
31,219 Points

The problem looks like you've modified the string you're echoing inside the if conditional - there's an extra 'also' in the string:

Hal's favorite flavor is also cookie dough, also!

If removing that doesn't pass the challenge, try removing the else statement as the challenge hasn't specified to include that.

1 Answer

Simon Coates
Simon Coates
28,667 Points

I think you changed the output text. It accepts:

<?php
$flavor = "Chocolate"; // task1
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor; //task2.
echo ".</p>";
if($flavor=="cookie dough"){//task3
echo "<p>Hal's favorite flavor is cookie dough, also!</p>"; //removed word here
}
?>