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 Basic PHP Website (2018) Listing and Sorting Inventory Items Review Basics

Cliff Jackson
Cliff Jackson
2,887 Points

can anyone figure this?

No one seems to be able to figure how to get the last part of line 3 to output correctly. I have tried a seperate echo and concatenation but neither work. Am i reading it wrong or is there a bug?

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

2 Answers

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

Hi there, Cliff Jackson ! You've got a couple of things going on here. First, you're missing the ending ?> tag. Secondly, we cannot be guaranteed that there is any function named get_flavor() in the file you've imported. The challenge just specifies that the variable is defined there. So you will not need the last line.

You can use either concatenation here (as you're attempting to do now) or you can opt to use the double quotation marks to expand the value of the variable in place (interpolation). However, your current echo statement would be correct except for two small things. You are missing an ending quotation mark after the last "." which is causing a syntax error and you forgot to account for a space before the $flavor. I would expect to see a space between "is" and the ending quotation mark there.

But again, you could opt to not use concatenation at all. It's likely simpler to use the interpolation.

For example:

<?php
  $student = "Cliff";
  echo "Hi there, $student!  Nice to meet you.";
?>

This would echo out "Hi there, Cliff! Nice to meet you." By using the double quotation marks we can expand the variable in place without concatenation.

Hope this helps! :sparkles:

Cliff Jackson
Cliff Jackson
2,887 Points

Hi Jennifer, The challenge passes until stage 3 and then fails every time no matter what way you try to output the variable, if you remove the line 4 it fails.

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

Hi there, again, Cliff Jackson. Sorry about that, you are correct that in step 2 you need to call the get_flavor() method. But again, you had a syntax error in your code. Furthermore, you have to call it before the echo statement. You are trying to echo out a variable that does not yet have a value.

I can get it to pass with both concatenation and without.

Take a look:

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

?>

The echo line could also be:

// note how I h ave an extra space after is and another quotation mark after the ending full stop
echo "Hal's favorite flavor of ice cream is " . $flavor . ".";

Either one of those pass for me. Hope this helps! :sparkles:

Hey Cliff

It would be useful for the community if you selected Jennifer's answer as best answer, so we know your question has been resolved.

Thanks