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

Problems in the code challenge

Hi There, I'm trying to do the code challenge with Variables and Conditionals. I pass stage 3 and move on to stage 4. When I get to stage 4 I change my favourite flavor to cookie dough and it says that stage 3 is no longer valid. I really don't understand where i'm going wrong. Please HELP! Best Regards Leanne

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

5 Answers

Ian Dow-Wright
Ian Dow-Wright
7,684 Points

The only difference between the code you've posted and the code that I used are:

ā€¢ In your echo statement you have wrapped your variable in "" which is optional but should still work.

ā€¢ You have removed the HTML tags that format the result of the PHP so your answer displays on one line instead of two.

My code was:

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

I hope that helps.

Ian Dow-Wright
Ian Dow-Wright
7,684 Points

Hi Leanne,

That's odd. Once you change the $flavor to "cookie dough" the message should display. Therefore stage three would no longer be valid as the goal of that is to make the message not display.

I'm wondering if there is some odd glitch causing it. Can you post your code and I'll try and guide you if there are any mistakes in it? Otherwise I'm not really sure how to help you beyond showing you my answer and letting you compare it to yours.

Hi Ian, Thanks for your help This is my stage 4 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 favourite flavor is cookie dough also!"; }

?> Regards Leanne

It worked... It must have been because I changed the "original" code or something. Awkward little beggar. At least I know my code isn't terrible though. Thanks again for your help :D

Ian Dow-Wright
Ian Dow-Wright
7,684 Points

I think you can just go back to the main page that lists all the stages of the course and choose the next step. You don't have to complete the stages in order as far as I can tell. Good luck.