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 trialAurelian Spodarec
7,369 PointsThe 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
Jason Anello
Courses Plus Student 94,610 PointsHi 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?
Tawny Bartlett
24,674 PointsYou should also wrap your string in ""s, like $flavor = "vanilla"; ! :)
Shawn Stewart
7,746 PointsWrap 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!"
Aurelian Spodarec
7,369 PointsThank 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 :)
Jason Anello
Courses Plus Student 94,610 PointsShawn,
The instructions never ask you to change Randy's statement.
Aurelian Spodarec
7,369 PointsAurelian Spodarec
7,369 Pointsis its like
if ($Randy == $0cookie dought){ echo ="$Randy" }
something like that ? im not sure about it , not sure what i need to do
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsRandy'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.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.