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

guys i need your help

Challenge Task 3 of 3

You should have my favorite flavor of ice cream in a variable named $flavor, and now it's time to display it to the screen. Replace the underscores in the echo statement with the value from the flavor variable. (You can do this with concatenation or with separate echo statements: your choice. But be sure to leave the period at the end of the sentence in place.)

output.php
<?php
include('flavor.php'); 
$flavor = get_flavor(banana apple);
echo "Randy's favorite flavor of ice cream is __________.";

echo "Randy's favorite flavor of ice cream is ______________.";

?>

2 Answers

To echo a variable in an echo statement, you would simply use the concatenation operator being before and after the variable. In php, we use the period character (.) before and after the variable to signify that this piece of text is code that needs to be processed out via php. so for the following question, the answer would simply be this:

<?php
include('flavor.php'); 
$flavor = get_flavor(banana apple);

echo "Randy's favorite flavor of ice cream is " . $flavor . ".";

echo "Randy's favorite flavor of ice cream is". $flavor . ".";

The answer above should spit out the following, "Randy's favorite flavor of ice cream is banana apple." if you notice I also added quotation marks around the ending period (.) because the period is still part of the sentence. If they wanted us to end without the period then our echo statement would look different. IE

<?php
include('flavor.php'); 
$flavor = get_flavor(banana apple);

echo "Randy's favorite flavor of ice cream is " . $flavor;

echo "Randy's favorite flavor of ice cream is". $flavor;

I would still use the period on the left to connect the variable to the previous string but sense the sentence ends with the variable you don't have to use a period on the right of the variable because there's nothing left to concatenate.

Hope this helps you out.

Regards,

Shawn Jone

this is confusing task one