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
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsvariables and conditionals
having a bit of a challenge with challenge 3 0f 4 under the variables and conditionals section of how to create a simple PHP application. the question reads 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. my answer was
<?php
$flavor = "vanilla";
echo "flavor";
echo "<p>Your favorite flavor of ice cream is ";
echo "vanilla";
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
if ($flavor == "cookie dough.")
else {
}
?>
But i keep getting it wrong with "Bummer! Be sure to add a conditional to hide the message." any help on how to remedy this would be great Randy Hoyt
2 Answers
August Whitlock
1,632 PointsSo what it is asking you to do, is change the code from this:
<?php $flavor = "rocky road"; echo "<p>Your favorite flavor of ice cream is "; echo $flavor; echo ".</p>"; echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
to this
<?php $flavor = "rocky road"; 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>"; }
?> The whole concept here is that it wont show the final message, which reads "<p>Randy's favorite flavor is cookie dough, also!</p>, unless both your favorite flavor AND Randy's favorite flavor is cookie Dough.
When I did this challenge I added rocky rock to $flavor variable, so this last echo message didn't show on the screen. But if you change it to cookie dough, then it will.
Ruben Dario Gutierrez Sanchez
4,602 PointsAugust is right,
<?php $flavor = "chocoloco"; echo "Your favorite flavor of ice cream is "; echo $flavor; echo "."; if($flavor == "cookie dough")//here you check if your flavor is equal to Randy`s flavor { echo "Randy's favorite flavor is cookie dough, also!"; } else{};//and here if is not the same flavor just finish the script and the message if Randy is not displayed
?> so if you use seudo code is like this
flavor is equal to chocoloco print "Your favorite flavor of ice cream is " print chocoloco print "." if your flavor (in this case chocoloco) is equal to cookie dough do this: print "Randy's favorite flavor is cookie dough, also!" if your flavor is not equal to cookie doug do this: you don`t put any command so the script finish.
Sorry for my very bad english.