PHP Build a Basic PHP Website Listing and Sorting Inventory Items Review Basics

Cliff Jackson
Cliff Jackson
2,886 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
MOD
Jennifer Nordell
Treehouse Moderator

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,886 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
Jennifer Nordell
Treehouse Moderator

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:

Spenser Hale
Spenser Hale
18,327 Points

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