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

PHP Menu Footer Challenge 4?

I am working on the code challenge for variables and conditionals in the PHP menus and footer section of the course. Here is what is happening. Challenge 1-3 work great, challenge 4 asked us to change the "value" of the $flavor variable to cookie dough presumably to get the sentence about the guy liking the same ice cream type as you to appear in the browser. Well all three before work great but on the 4th challenge the ONLY thing I change is line 2 from $flavor = vanilla; to $flavor = cookiedough; and it produces an error saying Task 3 no longer works. Well I was told to change the value that made task three work, so what is happening here?

UPDATE: Got it to work by placing my value for $flavor in qoutation marks.

12 Answers

"cookie dough" vs "cookiedough"

What it was that worked was putting the value for $flavor in qoutation marks. So thanks, but I got it.

Glad you worked it out :thumbsup:

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

@Joe, Glad you got it worked out! Technically, you should be putting the value for all of them in quotation marks. If the value is only one word without any spaces, PHP can figure out you probably meant for the value to be a simple piece of text. If the value has a space in it, though, PHP can't quite figure out what you want to do without the quotation marks. It's best to always use quotation marks around pieces of text, like this:

$flavor = "vanilla";

@Randy Hoyt,

That makes sense, and I like the uniformed syntactical approach to it as well. You even mentioned that in the video if I recall.

Thanks all,

Joe

I am having a similar difficulty. I get to task 4 and am asked to change my variables value to "cookie dough", which tells me to just change $flavor = "vanilla"; to $flavor = "cookie dough"; — But I think I am missing something because when ran tells me that task 2 is no longer passing? Without giving me the answer can someone help me out here? This is driving me nuts. I went back and watched the video again but couldn't see what I was missing.

It sounds like you understand what needs to be done, but are just tripping up somewhere. Post the code you are using here.

I made it past step 3 last night, but forgot what I placed in the code. Below is what I have so far. Any help on stage 3 and 4 would be appreciated. I really want to understand this better. Thanks

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

I assume that in the second conditional "vanilla" shouldn't be used, but I am just plain stuck. Help!

I resolved this after examining the instructions. I didn't think to change the variable, and all the echo's to reflect what was being asked of me. My bone head mistake and I have finally finished the challenge.

EDIT: Good to see you figured it out!

Step three wants you to add one conditional around the final echo statement, and you are using two conditionals in your code. Basically, when you complete step 3, your code should look something like:

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

This checks to see if your defined $flavor is the same as Randy's ("cookie dough"). In step 4, all you're doing is changing your $flavor variable to "cookie dough" to make sure that you are able to enter inside of your conditional.

Thanks Sam. I appreciate you taking the time to give me some feedback. This makes much more sense now. Again, much appreciative.

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Great work!

I wanted to be sure to mention here a note about conditionals and semi-colons. In this particular example ...

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

... each PHP command that get executed inside the curly braces of the if statement needs a semi-colon after it. But the if statement itself doesn’t, and neither do the curly braces. Think of them as wrappers around PHP commands that need to be executed; they’re not exactly PHP commands themselves.