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
Le Var Range
Front End Web Development Techdegree Student 18,011 PointsI am having a problem with the last question in php quiz integrating validation errors.
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.)
<?php
include("flavor.php");
echo "Randy's favorite flavor of ice cream is" . $flavor. ".";
return $flavor = get_flavor();
?>
This is what I have so far .. I am stuck.
4 Answers
Vittorio Somaschini
33,371 PointsHello Le Var Range .
You will need to add a space right after the word "is" in the echo statement.
Also, I would not put a return statement here. I would simply declare the $flavor variable like this: $flavor = get_flavor();
Be sure to put the variable declaration before actually its usage, so right above the echo statement line should do.
Kindly let me know if this works.
Ty
Vittorio
Le Var Range
Front End Web Development Techdegree Student 18,011 PointsTHANK YOU!! … what was wrong with my code is that I did not add a space at the end of the string … after the ( is ) in the echo statement. I remember slightly of the tutorial mentioning abt adding the space after the string. I don't understand why this is. It was a detrimental factor of me not solving the quiz question. I did declare the var after the echo statement and it still didn't work .. only until I added the space after the is .. did it work … Why is it so important in PHP to add a space after a string to concatenate?
Vittorio Somaschini
33,371 PointsIt is not important at all for concatenation in general..
It is important for passing the exercise as without the space you would print out (// let's presume $flavor = CREAM)
Randy's favorite flavor of ice cream isCREAM.
If you put the space it would print Randy's favorite flavor of ice cream is CREAM.
Which is what the teacher wants you to do.
jasonjones5
Courses Plus Student 5,571 PointsI'm completely stumped by this. I've tried a range of methods for concatenation/adding variables to strings and none of it is working. I've also tried directly copying the above solution and that did not work either. I've also played with that solution in multiple ways. I've declared the variable above the statement as "" "0" get_flavor() and $flavor but it didn't help so I took it out. If someone could point out what I'm doing wrong I'd appreciate it.
<?php
echo "Randy's favorite flavor of ice cream is " . $flavor. ".";
include 'flavor.php';
$flavor = get_flavor();
return;
?>
Susan Parker
14,473 PointsHere is my code that passed. I think I see a space missing in your echo command too, between the end of $flavor and your next concatenation period.
<?php
include("flavor.php");
$flavor = get_flavor();
echo "Randy's favorite flavor of ice cream is " . $flavor . ".";
?>