Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

I am working on the code challenge for variables and conditionals. I don't understand what is being asked in step 4.

So far we have assigned a variable, checked the variable to see if it matches, and if it does either display or hide a second message. I though step 4 was asking for the variable to be changed so that the second message would print, but outright changing the variable or reassigning the variable breaks the earlier part of the challenge. What are we being asked to do?

3 Answers

Yes, but if you do that, it tells you the earlier steps are broken. What they wanted (found through trial and error) was for you to copy and past the entire code block again, and then change the variable.

Must be a glitch because I just finished the challenge with the code block I posted above. You finished the challenge, so that's the most important outcome, besides trial and error is always the best way.

The task says to change the value of the initial variable you declare in task 1. In my case, I initially declare my $flavor as "vanilla" but then changed it to "cookie dough" to pass the fourth task.

<?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>";
}
?>
Frank Dillon
Frank Dillon
7,158 Points

In step 1 you're told to declare the "flavor" variable on line 2 as something other than "cookie dough".

In step 2 you ECHO the variable instead of the STRING "vanilla"

In step 3 you make sure your IF block works in that the second sentence is not displayed because your flavor is not "cookie dough". Remember in the IF block to compare strings you have to use the double = ( IF ($flavor == 'cookie dough')....)

In step 4 you have to change the declare statement to "cookie dough" ($flavor = 'cookie dough';) to validate that your that your IF block works correctly.