Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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