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

Why is this code wrong?

<?php

$flavor = "cookie dough";

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

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

I think they want you to concatenate the string like so :

<?php
echo "Your favorite flavor of ice cream is " . $flavor . ".";

BUT i didnt even read the assignment, short on time ;)

2 Answers

I am assuming you are on Challenge Task 1? I don't know if you copied your code over wrong but you have too many php tags in your code.

The below code is what you are after.

<?php 

$flavor = "cookie dough";

echo "Your favorite flavor of ice cream is "; echo $flavor; echo ".";

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

?>

If you compare the 2 codes you will be able to see where you have gone wrong with some syntax. You were close :)

Thank you for your great help! :)