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
abdul faiz mohd jayramie eng
Courses Plus Student 4,478 PointsPHP Variables and Conditionals. What went wrong?
this code challenge 2/4 task for Variables and Conditionals is driving me insane. took me about 2 hours figuring out with no solution after reviewing previous videos various times.
Here is the question: "Modify the command that displays the flavor of ice cream. Instead of it displaying a static piece of text, change it to display the value stored in the 'flavor' variable."
My Code:
<?php
$flavor = "<p>Your favorite flavor of ice cream is ";
echo $flavor; <!--NEWLY ADDED-->
echo "vanilla";
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
What went wrong?
12 Answers
Dawn Kesterson
885 Points<?php $flavor = "chocolate"; echo "<p>Your favorite flavor of ice cream is "; echo "chocolate"; echo ".</p>"; echo "<p>Randy's favorite flavor is chocolate, also!</p>";
?>
what I finally figured out and was getting tripped up on is---$flavor needs an actual flavor ie choco, vanilla, banana then the 1 echo statement must match that favor and finally Randy's favorite flavor must be the same in order to work
Ismael Rac
Courses Plus Student 15,244 PointsThis Challenge is broken Fix Team i had my code 1000000000000% correct and would not pass
Randy Hoyt
Treehouse Guest TeacherI actually had cookie dough ice cream twice today!
Patryk Nowak
14,103 PointsYou ate something in your code :)
This code should work for you
<?php
$flavor="choco"; // this is my fav flavor
echo "<p>Your favorite flavor of ice cream is "; // missing line in you code
echo $flavor;
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
Magnus Braathen
7,726 PointsI tried running your code through the code challenge multiple times, removing your comments and additional space. It does not pass the challenge.
abdul faiz mohd jayramie eng
Courses Plus Student 4,478 PointsOMG!! thank YOU guys! saved me from suicide!
Claus Schmidt
2,357 Pointshi guys, this discussion was about task 2/4, I got a question about task 3/4 of the same challenge. unfortunately, I don't get it to work. my attempt looks like this:
<?php $flavor = "vanilla"; if ($flavor == "cookie dough") { echo "<p>Your favorite flavor of ice cream is "; echo "$flavor"; echo ".</p>"; }
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
first sentence disappears, but it won't let me pass the challenge??
Randy Hoyt
Treehouse Guest TeacherIt's the second sentence that needs to be wrapped in the conditional. The page should always say this:
Your favorite flavor of ice cream is strawberry.
However, it should only display the second sentence if your flavor is the same as mine.
Your favorite flavor of ice cream is cookie dough. Randy's favorite flavor is cookie dough, also!
Does that help?
Claus Schmidt
2,357 Pointsyes, thanks a lot! ..it worked
Magnus Braathen
7,726 PointsHey, for me not any of these replies helped me, compare my code to your own. The moderators comment wasn't too helpful either.
<?php
$flavor = "strawberry";
echo "<p>Your favorite flavor of ice cream is ";
echo "$flavor";
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
Magnus Braathen
7,726 PointsHey, for me not any of these replies helped me, compare my code to your own. The moderators comment wasn't too helpful either.
<?php
$flavor = "strawberry";
echo "<p>Your favorite flavor of ice cream is ";
echo "$flavor";
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
Magnus Braathen
7,726 PointsHey, for me not any of these replies helped me, compare my code to your own. The moderators comment wasn't too helpful either.
<?php
$flavor = "strawberry";
echo "<p>Your favorite flavor of ice cream is ";
echo "$flavor";
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
cathymacars
Full Stack JavaScript Techdegree Student 15,941 PointsWhat should be in the variable as it's value is only whats going to change in the phrase (the dynamic text). In this case, it is the ice cream flavor itself, not the phrase. So It should be like:
<?php
$flavor = vanilla;
echo "<p>Your favorite flavor of ice cream is "; <br />
echo $flavor;
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
So, when you change the value of the $flavor variable, it should also change the flavor written in the phrase.
Betsabeh Yeganeh
3,793 PointsBetsabeh Yeganeh
3,793 PointsIt works : <?php $flavor = "mint"; echo "<p>Your favorite flavor of ice cream is "; echo $flavor ; echo ".</p>"; echo "<p>Randy's favorite flavor is cookie dough, also!</p>"; ?>