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

Change the value in the flavor variable to cookie dough. Preview the code and make sure the message appears. Task 4 of 4

This challenge asks to change the value of the $flavor variable to "cookiedough". Once I do this, though, without making any other changes, it fails.

What am I missing?

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

?>

3 Answers

James Best
James Best
11,112 Points

Hey,

If you are submitting the code above the reason it is failing is that you have to assign cookiedough to the variable flavor. It is currently marionberrypie and so the if statement is failing and so I assume the quiz is failing.

Does that make sense?

Hope that helps

James

yes, i already said in my question "even after I change it, it still fails". I may have refreshed the page and the screenshot is from before I change the variable value. Even after I do, the challenge still fails.

Joe Mills
Joe Mills
18,617 Points

As James said the reason that code won't work is because the flavor variable is still set to marionberrypie so your if statement is reading false. You need to change the $flavor variable and make sure it's spelt the same in the variable as it is in the if statement like so:

$flavor = "cookie dough";

if ($flavor == "cookie dough") {

yes, i already said in my question "even after I change it, it still fails". I may have refreshed the page and the screenshot is from before I change the variable value. Even after I do, the challenge still fails.

James Best
James Best
11,112 Points

Ok so I went back and did the quiz again and the mistake in your code is so small it is easy to miss. The variable should be 'cookie dough' not 'cookiedough'. You are missing a space between the words and so the test is failing.

Hope that helps.

James