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

Groundhog's Day scenario in PHP Development

when I change the code I've created in Task 4 everything is great until I confirm it and then it tell me that my code in Task 3 is no longer valid. I'm in an insane loop of going back changing Task 3 to be correct, altering it for Task for to be correct and then getting a message telling me Task 3 is no longer correct.

HELP!!! Somebody!

Can you post the code that you're using to pass task 3 and then the code you are writing in task 4 which causes task 3 to no longer pass?

6 Answers

Hi Eric,

I went through the challenge again and I typed in your values. After staring at it for a while I realized that in task 3 you dropped the <p> tag around Randy's message.

I believe it still passed task 3 because the if statement is false at that point and the string never gets echoed. So the code checker probably isn't looking at that string.

In task 4 it does get echoed and the code checker is probably noticing that it's not wrapped in p tags.

Here's the code in order:

Task 3 <?php $flavor = "chocolate"; 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!";}

?>

This is the code for Task for that works in preview

Task 4 <?php $flavor = "chocolate"; 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 hit check code I get the following error message: Oops! It looks like Task 3 is no longer passing.

Rod Barbee
Rod Barbee
11,935 Points

Task 4 asks you to change the value of the variable $flavor to "cookie dough". Yours is still set to "chocolate"

OK I thought it would be better if I took screen shots of the lesson so everyone can see what happening, exactly. Rod, you are absolutely right. The code I pasted here in the forum was in error but that isn't the code I've been using (my mistake). I've actually been using the correct code.

Below is a link of a page I created on my website with screenshots (in order) of what's happening.

http://babathestoryteller.com/treehouse/

Let me know if you find anything wonky with the code in those screen shots.

Thanks for taking the time to review this! I mean it is really driving me nuts.

Rod Barbee
Rod Barbee
11,935 Points

Hi Eric, Look at line 4: echo "$flavor"; I don't think echoing the content of a variable should require quotes. See what happens if you remove them.

Hi Rod,

It turns out there's a difference between using single and double quotes. With double quotes, the variable would be evaluated. With single quotes, it would echo the string "$flavor". So you would see your variable name on the page and not its contents.

So double quotes around the variable will successfully pass task 2. It should pass without too.

There's some good info here about the 4 ways to specify strings in php for anyone interested:
http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php

Rod Barbee
Rod Barbee
11,935 Points

Thanks Jason, so much more to learn.....

You're welcome.

It never ends, and it feels overwhelming at times. In this industry, we'll never be done with learning. The technology changes too rapidly.

Jason, you're absolutely right! I'm learning a valuable lesson. Having had a "little" coding experience is a dangerous thing. I removed the <p></p> tags for some unknown reason, not sure why I did that, but when I placed them back in the code worked.

I really appreciate the responses from both you and Rod. I'm scratching my head right now trying to think of what led me to make such a bonehead decision. Hmmm....