Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Enhancing a Simple PHP Application Integrating Validation Errors Reviewing PHP Basics

Kristopher Hutchison
Kristopher Hutchison
2,450 Points

Challenge says $flavor is not being echoed. I'm pretty sure my answer is correct. Could this be a bug?

Not sure why $flavor is not echoing to page. I've even tried placing my echo statement below the return.

output.php
<?php
include_once('flavor.php');
echo "Randy's favorite flavor of ice cream is ".$flavor.".";
$flavor = get_flavor();
return $flavor;

?>

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

The big problem here is that you're trying to echo something you haven't gotten yet. You have to define the flavor variable then call the method that's in the flavor.php file and set the value of flavor to the value returned by that method. The minor thing is that you don't need a return statement at all. Your code isn't wrong per sé... it's just a bit misordered. Take a look at my solution:

<?php
include_once('flavor.php');
$flavor = get_flavor();
echo "Randy's favorite flavor of ice cream is ".$flavor.".";

?>

Moral of the story: in most languages you can't use a variable you haven't defined yet. Happy coding!