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

Code Challenge Variables and Conditions - Final Challenge

Hey Guys

I've been stuck on this challenge

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

My Code

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

?>


I believe im doing what the challenge is asking. Yet im still getting a "Oops" error. I've tried this with several different options with the same result.

Please advise and thank you in advance.

hint 1: you declared the $flavor variable twice. Once with value of vanilla and second time (which overwrites the first value) you set it to cookiedough. Should be declared only once. If this is the step 4/4 then $flavor should have a value of "cookie dough. hint 2: your final output should read: your favorite flavor of ice cream is cookie dough. Randy's favorite ice cream is cookie dough also.

6 Answers

Hello guys I too am having an issue with 4/4 my code:

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

When I preview it the code works as it should

However when I submit it this error is thrown back:

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

Just make one $flavor variable and give it a value of "cookie dough" then make the second echo statement have a value of $flavor.

Next take the first conditional out and then put the last echo statement in curly braces.

Hope that makes sense and helps.

Thanks for the response Chase.

I keep getting a "Oops! It looks like Task 2 is no longer passing."

Am receiving the correct answer through.

(Randy's favorite flavor is cookie dough, also! )

<?php

$flavor = "cookie dough"; if ($flavor == "vanilla")

echo "Your favorite flavor of ice cream is ";

$flavor = "cookie dough";

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

Take out:

if ($flavor == "vanilla")

And the second:

$flavor = "cookie dough";

Then echo $flavor after your first echo statement and the a period.

What an aha moment. My code finally worked.

Thanks guys for the quick responses.

i keep on getting this: Bummer! Be sure to add a conditional to hide the message.

here is my code-

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