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

PHP Website

Somebody answered this challenge ?

Challenge Task 1 of 3

This block of code displays two sentences related to flavors of ice cream. In this code challenge, we'll modify the code block to use a variable and a conditional. First, create a new variable named flavor and assign your favorite flavor as the value. (Add this command at line 2. Don't forget to use a dollar sign in the variable name, and don't forget to end your command with a semi-colon.) Important: The code you write in each task should be added to the code written in the previous task. Preview Get Help Reset Code Check Work index.php

1 <?php 2 ​ 3 echo "<p>Your favorite flavor of ice cream is "; 4 echo "vanilla"; 5 echo ".</p>"; 6 echo "<p>Hal's favorite flavor is cookie dough, also!</p>"; 7 ​ 8 ?> 9 ​

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

Matthew Bilz
Matthew Bilz
15,829 Points

Part 1: You would assign a string value to a variable called $flavor noting your favorite ice cream flavor, i.e.

$flavor = "Chocolate";

You would then remove the second echo statement's string value of "vanilla" and simply echo out your $flavor variable, i.e.

echo $flavor;

I'm guessing the conditional (if/then) wants the 4th echo line to happen when your favorite ice cream flavors are the same, so you'd create the statement like this and replace the 4th line's current echo statement with the following:

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