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

General Discussion

Brad Webster
Brad Webster
1,642 Points

Code Challenge: Variables and Conditonals

Here is my code:

<?php $flavor = "cookie dough";

echo "<p>Your favorite flavor of ice cream is $flavor";

echo ".</p>";

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

The browser to the right displays the two sentences (as it should), but I get the message "Oops! It looks like Task 3 is no longer passing."

What am I doing wrong?

3 Answers

Dale Gardner
Dale Gardner
9,838 Points

In that code challenge the $flavor variable is output in a separate echo statement. echo $flavor;

It would probably accept it in the same line as well, but your syntax is wrong. You could concatenate like so: echo "Your favorite flavor of ice cream is " . $flavor;

This code passes challenge four:

<?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>";
}
?>
Brad Webster
Brad Webster
1,642 Points

Awesome, it worked! Thanks, Ernest. And Dale.

I think the confusion came in Task 3; when I originally entered in the code, I left in the "paragraph" tag, but it didn't work. Once I removed the tag, it worked. That was last night.

Today, when I tried the code with the "paragraph" tag included, it worked. So I don't if maybe something was going wrong with the website, or I'm just mistaken about what code I entered.

Either way, it works now. Thanks again!

Nathan Goode
Nathan Goode
14,789 Points

I know this is an old thread now, but had to comment. I had the same issue Brad. For some reason, Task 3 only seemed to work when I removed the <p> tags from "Randy's favorite flavor is cookie dough, also!", but would only work on Task 4 when the <p> tags were included.

So I can get my head around this, can anyone elaborate on why this would be the case? Is it a problem with the challenge, or is there a reason why the <p> tags are not required one question, but are the next?

Hope that question makes sense?

Cheers Nath