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

The message in the final echo command only makes sense if your favorite flavor is the same as mine. Add a conditional ar

Hello , Can somebody help me please with this code challenge.

@The message in the final echo command only makes sense if your favorite flavor is the same as mine. 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.

<?php

$flavor = vanillia; echo "<p>Your favorite flavor of ice cream is "; echo "$flavor"; echo ".</p>"; echo "<p>Randy's favorite flavor is cookie dough, also!</p>";

?>

3 Answers

Hi Aurelian,

You want to wrap the "Randy" statement in an if block so that it is only output when your favorite flavor matches Randy's which is "cookie dough"

What part are you not sure about? Do you know how to set up an if block?

is its like

if ($Randy == $0cookie dought){ echo ="$Randy" }

something like that ? im not sure about it , not sure what i need to do

Randy's statement should be echoed when your favorite flavor is cookie dough. Randy's favorite flavor is cookie dough and so when your favorite flavor is also cookie dough then that statement should be echoed.

Since your favorite flavor is stored in the $flavor variable the proper condition is $flavor == "cookie dough" That checks if your favorite flavor is equal to cookie dough. Right now for task3 your favorite flavor is vanilla and so this condition will not be true and Randy's statement will not be echoed.

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

?>

Also, as Tawny pointed out, you need to wrap vanilla in quotes. You don't need double quotes around $flavor in the 3rd line of code but it works the same with them.

So at the end of task 3, Randy's statement should not be echoing out if you check the preview.

Tawny Bartlett
Tawny Bartlett
24,674 Points

You should also wrap your string in ""s, like $flavor = "vanilla"; ! :)

Shawn Stewart
Shawn Stewart
7,746 Points

Wrap the sentence in the if conditional, like so: if ($flavor == "vanilla") { echo "Randy's favorite flavor is cookie dough, also!"; }

Then, replace "cookie dough" your variable. You will need to concatenate the string.

echo "Randy's favorite flavor is " + $flavor + ", also!"

Thank you all . Bdw i didnt reply because i had an eye infection so i coudnt use any electronic devices :/ but this is really helpful thank you :)

Shawn,

The instructions never ask you to change Randy's statement.