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

PHP Build a Simple PHP Application Creating the Menu and Footer Variables and Conditionals

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.

Been working on this and getting tons of wrong answers and am very frustrated. What should this answer be. I am going to cancel my membership with teamtreehouse if someone doesn't answer me with code that 100% works. I have had enough now going 4 hours on one stupid challenge.

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

?>

Vaughn Lawson
Vaughn Lawson
3,483 Points

Hi all, this code worked for me, hope this helps. <?php $flavor = "vanilla"; echo "<p>Your favorite flavor of ice cream is "; echo $flavor; echo ".</p>"; echo "<p>Hal's favorite flavor is cookie dough, also!</p>";

?>

Please note no "" around the echo $flavor.

35 Answers

challenge 2 asked:

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.

I had the following which worked for me:

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

?>

Thanks for trying. I will try to find someone in this company that can fix this if not I'm not wasting any more time with this. Thanks again.

Paul Franz
Paul Franz
4,461 Points

I think you're kind of overreacting. There have been times a code challenge hasn't parsed for me because of some tricky text, but usually I find out I made a mistake somewhere.

Passed this awhile ago without any problems, so I'd recommend re-reading the directions and making sure you're following them exactly.

Your attitude here is kind of a turn-off for people who may want to help you.

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

?>

Bummer! Be sure to update the output to include your flavor, without changing any of the other code.

<?php

echo "<p>Your favorite flavor of ice cream is "; echo "vanilla"; echo ".</p>"; echo "<p>Hal's favorite flavor is cookie dough, also!</p>"; $flavor = "tomato"; echo"Your favorite flavor of ice cream is"; echo$flavor; echo"."; if($flavor=="Mint") echo "So my favorite flavor is Tomato "; ?>

This code works for me

<?php $flavor = "nuts";

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

<?php
$variable = "Cookie dough";

echo "<p>Your favorite flavor of ice cream is ";
echo $variable;
echo ".</p>";
if ($variable = "cookie dough") // Evaluates to TRUE  
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";

?>

If you copy and paste this and click 'check work' you will get a wrong answer,

But I have presented you with the structure! Take a break! come back in a couple of hours. You will feel better and probably pass the task.

I am not able to pass this code challenge either...

i have spent around 3 to 4 hours on this. I look at all the forum posts, but they don't seem exactly accurate or relevant to me or my case???

its very disconcerting...this is not hard...all the answers given I already have in my mind and have tried them, but they all fail...can someone help?

take a look at these screen shots as they best illustrate the situation: http://screencast.com/t/ROY4HHLSbfNk you can see here I passed code challenge 3 with the correct answer. (despite no need for "quotation marks" strangely???)..even if i add the quotation marks taks 3 fails! anyway... i carry on.

but as you can see when i move to task 4 http://screencast.com/t/HrANRVbtTjot once I change the "flavor variable" to "cookie dough" i know that I am supposed to put something like "{ echo "Randy's favorite flavor is cookie dough, also!"; } ?> but i dont get why nothing I try works? you dont see any code there yet, because I have tried everything. for hours and hours. what do i do? i looked at all your posts and threads and tried so many variations. I just want to move on...

is there a way to keep carrying on with learning even if we cannot pass a code challenge? I dont believe that my not passing this code challenge reflects a true lack of capability , skill or understanding.

I want to move on! can someone help?

This guy gives the worst tests

Helga, I just got this one finally. Thanks for your help. Everyone else, sorry I got so frustrated and had a bad attitude. I was just kicking my butt on a bad day...lol. Thanks everyone that gave input.

Shilpa Kothari
Shilpa Kothari
4,518 Points

Hi Randy

I also tried working on this code but I am still not getting it. can you tell what exactly you did?

Thanks Shilpa

<?php

$flavor ="vanilla"; echo "Your favorite flavor of ice cream is ". $flavor . "."; echo "Randy's favorite flavor is cookie dough, also!";

// you can also save cookie dough to a variable and then echo it as part of your string like so:

$fav_flavor = "cookie dough"; echo "Randy's favorite flavor is " . $fav_flavor . ", " . "also!";

?> // end of php script

Hope this helps let me know

I get this error message:

Bummer! Be sure to update the output to include your flavor, without changing any of the other code.

Error message is now

Oops! It looks like Task 1 is no longer passing.

//This should work:

<?php $flavor = "mint";

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

?>

Thank you sooo much Helga. Finally it works.

no worries. glad to be of help.

I spoke too soon. It had reset my to challenge 1 then it didn't work on challenge 2 ugh!!!

I need to know exactly where you are stuck and what you are having problems with to help

paste the instructions and code you are struggling with here

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.

I used your code:

<?php $flavor = "mint";

echo "Your favorite flavor of ice cream is "; echo $flavor; echo ".";

if($flavor=="cookie dough") echo "Randy's favorite flavor is cookie dough, also!";

?>

I get this error:

Bummer! Be sure to update the output to include your flavor, without changing any of the other code.

That was not my code exactly. This is my code and it worked:

<?php $flavor = "mint";

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

?>

Still error:

Bummer! Be sure to update the output to include your flavor, without changing any of the other code.

Same error: Bummer! Be sure to update the output to include your flavor, without changing any of the other code.

you are on task number 2 right?

Yes

Then the code I gave above should work as it works for me in my editor not sure why it does not work for you. If you can paste exactly the screenshot of what you wrote in your editor maybe I could help. But other than that, I gave you the same exact code I ran on my editor which worked for me. You may have to exit the editor and come back again into the task and try again.

<?php $flavor = "mint";

echo "Your favorite flavor of ice cream is "; echo $flavor; echo "."; echo "Randy's favorite flavor is cookie dough, also!";

?>

What did you put for task 1? Maybe that is where the problem is coming from.

for task 1 :

<?php $flavor = "mint";

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

?>

Same here. I exited out and then resumed and have the same code has you for task 1 and no problem. Code for task to keeps giving me that same error:

Same error: Bummer! Be sure to update the output to include your flavor, without changing any of the other code.

Copied straight out of challenge 2:

<?php $flavor = "mint"; echo "Your favorite flavor of ice cream is "; echo $flavor; echo "."; echo "Randy's favorite flavor is cookie dough, also!";

?>

sorry not sure how else I could help

Task 1 instructions were:

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.)

and I had the following and it worked for me:

<?php

$flavor = "mint";

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

?>

no worries best wishes

Will Vincent
Will Vincent
2,594 Points

It does not work 4 me

Vipin Singh
Vipin Singh
15,268 Points
<?php

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