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
Jeffrey Vierra
25,404 PointsCode 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.
6 Answers
Kiya Appling
Courses Plus Student 3,959 PointsHello 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.
Chase Lee
29,275 PointsJust 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.
Jeffrey Vierra
25,404 PointsThanks 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!";} ?>
Chase Lee
29,275 PointsTake out:
if ($flavor == "vanilla")
And the second:
$flavor = "cookie dough";
Then echo $flavor after your first echo statement and the a period.
Jeffrey Vierra
25,404 PointsWhat an aha moment. My code finally worked.
Thanks guys for the quick responses.
Christian Torres
3,795 Pointsi 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 "."; ?>
Pavol Almasi
Courses Plus Student 1,524 PointsPavol Almasi
Courses Plus Student 1,524 Pointshint 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.