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

Don Shipley
Don Shipley
19,488 Points

PHP

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.

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

<?php $flavor = "favorite flavor"; echo "<p>Your favorite flavor of ice cream is "; echo $flavor = "vanilla"; echo ".</p>";

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

In the videos he explain how to use the variable setting in different pages. I am lost on how to reset the variable on the same page.

Nathan Newell
Nathan Newell
7,634 Points

why do you want to reset? in what context are you wanting to reset the variable for in this code.

Don Shipley
Don Shipley
19,488 Points

It is a test question. On the top is the question..

3 Answers

Nathan Newell
Nathan Newell
7,634 Points
<?php
$flavor = "cookie dough";
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>";
}
?>
Don Shipley
Don Shipley
19,488 Points

Thank you for your help but this will mess up the first variable of vanilla. The problem I see is on the videos he makes a variable on one page and changes then on other pages. On the test the first question is to make a variable named flavor $flavor = "favorite; second is instead of text echo "vanilla"; to change to the variable. echo $flavor = "vanilla"; Third question is to set a condition the read cookie dough and hide the output. if ($flavor = "cookie dough){echo "Randy's favorite flavor $flavor , also!} passed all to this point forth question change the $flavor to cookie dough.

Nathan Newell
Nathan Newell
7,634 Points

exactly... you need to change the code so ...

$flavor = "cookie dough";

only once you have done that will the IF condition be true and the echo will display.. ignore the previous questions and consider this separate.

Don Shipley
Don Shipley
19,488 Points

I have done that , If you preview it you can see the way it is suppose to look. Click on the submit button and it does not pass What I wrote <?php $flavor = "favorite"; echo "<p>Your favorite flavor of ice cream is "; echo $flavor = "vanilla"; echo ".</p>"; $flavor ="cookie dough"; if($flavor == "cookie dough"){ echo "<p>Randy's favorite flavor is $flavor, also!</p>";} ?>

Don Shipley
Don Shipley
19,488 Points

Oops! It looks like Task 2 is no longer passing This is what the test shows after submitting the answer.

Again thank you for your help