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
Tony McCabe
8,445 PointsReviewing PHP basics
Lesson:
http://teamtreehouse.com/library/reviewing-php-basics
Question 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.)
My code:
<?php
include("flavor.php");
$flavor = get_flavor();
echo "Randy's favorite flavor of ice cream is ____.";
echo $flavor
?>
What are you asking a little confused, Sorry!
13 Answers
Ernest Grzybowski
Treehouse Project ReviewerHey Tony McCabe,
I'd be happy to help you out. First, I just want to let you know that it would be simpler to help you if you were more detailed on exactly which lesson you are on. There are hundreds of lessons on treehouse, and it get's a little difficult to help when it's not clear where you currently are. Something like http://teamtreehouse.com/library/reviewing-php-basics will suffice. I've edited your question to reflect some of these changes to make it easier to read, and for you to use as a possible template for future questions.
On to the question!
So the question is basically asking you to fill in the ____ with the variable $flavor which you already declared correctly.
The question also let's you know that you can use concatenation or you can use multiple echo statements.
I'll go through both.
Concatenation:
<?php
include ("flavor.php");
$flavor = get_flavor();
echo "Randy's favorite flavor of ice cream is ".$flavor.".";
?>
Multiple echo statements:
<?php
include ("flavor.php");
$flavor = get_flavor();
echo "Randy's favorite flavor of ice cream is ";
echo $flavor;
echo ".";
?>
Both of those answers are valid and pass the code challenge. Hope that helps!
Heber Pavon
4,456 PointsFirst Answer
<?php
$flavor = "Vanilla";
echo "<p>Your favorite flavor of ice cream is ";
echo 'vanilla';
echo ".</p>";
?>
Second Answer
<?php
$flavor = "Vanilla";
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor;
echo ".</p>";
?>
Third Answer
<?php
$flavor = "Vanilla";
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor;
echo ".</p>";
if($flavor == "cookie dough"){
echo "<p>Hal's favorite flavor is $flavor, also!</p>";
}else{
echo'';
}
?>
Riley Hilliard
Courses Plus Student 17,771 PointsThe challenge wants you to replace the "_____" with the php code that will generate the favorite flavor ( which is stored in the variable $flavor ) I would guess it should look something like this:
<?php
include("flavor.php");
$flavor = get_flavor();
echo "Randy's favorite flavor of ice cream is " . $flavor . ".";
?>
IHAMMOUTEN said
Courses Plus Student 8,714 Pointstry this it's really work for me
$flavor = "cookie dough.";
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor;
echo ".</p>";
if ($flavor == "cookie dough.") {
echo ".</p>";
}
?>
Brian Salman
2,601 PointsI'm having trouble with this challenge question as well. The area is Creating the Menu and Footer. The Code Challenge: Variable and Conditionals.
Here is the exact question from the challenge and the coding that has been edited by the three previous questions within the challenge. The answers you have given us were not taught in this particular lesson.
QUESTION: The message in the final echo command only makes sense if your favorite flavor is the same as mine. Add a conditional around that final echo command that checks if the flavor variable has a value of "cookie dough." (Remember to choose carefully between using a single equal sign and a double equal sign in the check.) Preview the code and, if you have a different flavor, make sure the message disappears.
<?php $flavor = "cookie dough"; echo "<p>Your favorite flavor of ice cream is "; echo "$flavor"; echo ".</p>"; echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
Thank you in advance for your help!
Stefan Santana
5,836 PointsHey Brian,
I tried this and got it through:
<?php $flavor = "cookie dough"; if ($flavor == "cookie dough") { echo $flavor; } echo "<p>Your favorite flavor of ice cream is "; echo $flavor; echo ".</p>"; echo "<p>Randy's favorite flavor is $flavor, also!</p>";
?>
It looks like you overlooked the conditional. Hope this helps.
Melvin Ho YK
Courses Plus Student 25,247 PointsI almost tear my hair out till I'm through the "if" conditionals statement. Here's my take: <?php $flavor = "Your favorite flavor of ice cream is "; $flavor = "vanilla"; if ($flavor == "cookie dough") { echo "<p>Randy's favorite flavor is cookie dough, also!</p>"; } echo "<p>Your favorite flavor of ice cream is "; echo "vanilla"; echo ".</p>"; ?>
Melvin Ho YK
Courses Plus Student 25,247 PointsSorry over the spelling check for "through". Just add a "if" statement after $flavor vanilla. And cut out echo last line "favorite flavor cookie dough" to put inside the curly braces of the 'if' statement. Ignore the <p> syntax. :)
Riccardo Marotta
10,875 Pointshi, my code in the task three is that one. why it continues to say that task one is no longer passing? thanks
<?php include('flavor.php'); $flavor= get_flavor(); echo "Randy's favorite flavor of ice cream is ".$flavor."."; ?>
Ashenafi Ashebo
15,023 Pointsecho "Hal's favorite flavor of ice cream is ". $flavor . "."; this one work for me.
Juliano Vargas
Courses Plus Student 15,575 Pointsecho "Randy's favorite flavor of ice cream is" . $flavor . ".";
this is what i have got i am here for half hour and thinking it can't be wrong after all all that i was missing was the space b4 is
echo "Randy's favorite flavor of ice cream is " . $flavor . ".";
:(
Unsubscribed User
5,869 PointsThe code below will work but make sure to delete spaces for < p > and < / p > in the code. Without spaces will not display here so that is why there are spaces for your pleasures.
<?php $flavor = "cookie dough."; echo "< p >Your favorite flavor of ice cream is "; echo $flavor; echo ".< / p >"; if ($flavor == "cookie dough.") { echo "."; } ?>
Hass Beydoun
8,625 PointsMan that was an annoying one
ninyo
15,367 PointsThis code worked for me.
- First the idea is to encapsulate the last line to be executed after an if() statement equals true. Here is the code we start out with:
<?php
$flavor = "cookie dough";
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor;
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
- Encapsulate the whole line inside {pointed brackets} even with the semi-colon inside. This will be placed after the completed if() statement, which the statement is set to ($flavor == "cookie dough"). Which in this case, $flavor is set to "cookie dough", and since "cookie dough" is equal to "cookie dough", allows the following code to run:
<?php
$flavor = "cookie dough";
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor;
echo ".</p>";
if($flavor == "cookie dough"){echo "<p>Randy's favorite flavor is cookie dough, also!</p>";}
?>
- and for minimalization:
<?php
$flavor = "cookie dough";
echo "<p>Your favorite flavor of ice cream is ";
echo $flavor;
echo ".</p>";
if($flavor == "cookie dough"){echo '<p>Randy\'s favorite flavor is ' .$flavor. ', also!</p>';} //use concatenation while canceling the apostrophe with the \ key to remove repeated strings
?>
(I had problems on this too, so typing this out helps me understand this situation myself and hopefully it helps anyone along the way as well) thanks~
Darrel Lyons
2,991 Points.
ninyo
15,367 Pointsbefore he deleted his comment ^ "You echoed a variable here and you tell me you don't echo a variable. I passed my quiz with that i wrote below. You've not learnt off this site then."
Lol. It's not about passing the quiz, that's not the idea. It's about keeping consistent with the concept of keeping the variable out of the string when sourcing a variable name. Hense concatenation.
No need to be upset either. We're all learning. Cheers
Darrel Lyons
2,991 PointsYou all made it more difficult than it had to be. Here is the easiest way:
<?php
$flavor = "chocolate";
echo "<p>Your favorite flavor of ice cream is ";
echo "$flavor";
echo ".</p>";
echo "<p>Randy's favorite flavor is $flavor, also!</p>";
?>
ninyo
15,367 Pointsyou don't echo a variable
Darrel Lyons
2,991 PointsIt worked for me. Easy as pie.
Yan Cruz
20,439 Points<?php include("flavor.php"); $flavor = get_flavor(); echo "Randy's favorite flavor of ice cream is cookie dough."; echo $flavor ?>
That's the code I used to pass the challenge
Joshua Paulson
37,085 PointsJoshua Paulson
37,085 PointsBeen trying to complete this task but every time it says task one is no longer passing.
This has been kinda frustrating
I have:
<?php include ("flavor.php"); $flavor = get_flavor(); echo "Randy's favorite flavor of ice cream is "; echo $flavor; echo ".";
?>