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

Could you please help with this code challenge?

2 Answers

Hello Leon,

This is how your code should look like to pass the challenge. However, you could simplify it even further, but I'm sure you will be learning about that in a future assessment.

<?php
$flavor = "vanilla";

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>";
} else {
  echo "<p>Seems like you and Randy have different taste.</p>";
}
?>

For stage 4 of the challenge, simply change the variable to this:

<?php
$flavor = "cookie dough";
?>

I don't know why they would make us put an else statement in if we didn't learn it.

I apologize, I haven't taken that course and had no idea that you haven't learned about the else statement yet. It is not necessary to include it in order to pass the challenge. You can simply remove it and the code will still validate.

<?php
$flavor = "vanilla";
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>";
}
?>

No, no, you were in no wrong. The code above was completely correct, I still thank you for your help.