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

Task 4 of code challenge 1 in PHP development

Hi there,

Here is the code that I've written for task 4: <?php

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

I believe that code works fine but it keeps telling me that task 2 doesn't pass. Therefore, can anyone help me about this problem :(

2 Answers

Chris Dziewa
Chris Dziewa
17,781 Points

My working code:

<?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>";
endif;
?>

Note that you can use { } instead of my : and endif but right now you are reassigning the variable $flavor when you only need to replace "vanilla" on the first line with "cookie dough".

ooh :( I thought the task is to keep the output "Your favorite floavor of ice-cream is Vanilla" :-P Now, let me redo this again

Thank Chris

Chris Dziewa
Chris Dziewa
17,781 Points

No problem, Long! Here the test was just looking for you to change your favorite flavor so it outputs the conditional statement.