Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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 ā€‹


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

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>";