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 trialCliff Jackson
2,887 Pointscan 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?
<?php
include "flavor.php";
echo "Hal's favorite flavor of ice cream is". $flavor .".;
$flavor = get_flavor();
2 Answers
Jennifer Nordell
Treehouse TeacherHi 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!
Cliff Jackson
2,887 PointsThanks Jennifer!
Cliff Jackson
2,887 PointsCliff Jackson
2,887 PointsHi 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
Treehouse TeacherJennifer Nordell
Treehouse TeacherHi 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 theecho
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:
The echo line could also be:
Either one of those pass for me. Hope this helps!