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 trialStormy Silver
9,240 Pointstask 2:
task 2: Modify the command that displays the flavor of ice cream. Instead of it displaying a static piece of text, change it to display the value stored in the 'flavor' variable.
this is what i have so far:
<?php $flavor = "mint";
echo "Your favorite flavor of ice cream is "; echo $flavor; echo "."; echo "Randy's favorite flavor is cookie dough, also!";
?>
I've been working on this for hours now and I just cant figure it out, help please.
3 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Stormy,
I think your code is fine except that you've somehow lost all the <p>
tags. I'd paste in the correct code for task 2 so you could compare but it seems to be down again.
Here's the starter code:
<?php
echo "<p>Your favorite flavor of ice cream is ";
echo "vanilla";
echo ".</p>";
echo "<p>Randy's favorite flavor is cookie dough, also!</p>";
?>
Go back to your code and make sure you put in all the opening <p>
and closing </p>
tags that you see here and you should be ok.
The problem might be that the code checker is looking for your output to be inside a paragraph and your code as you've posted it would not match that.
Richard Duncan
5,568 Pointsecho "Your favorite flavour of ice cream is ".$flavour;
No need to echo again in the string. You could also achieve this with the variable named wrapped in {} no need for the period but this will not be accepted as an answer and is bad practice really these days but you may come across it.
Jason Anello
Courses Plus Student 94,610 PointsHi Richard,
Concatenation isn't covered at this point in the course. I'm not saying it's wrong but it could lead to more confusion.
The period that is being echoed is so that the sentence can end in a period.
Andrew McCormick
17,730 Points**As @Jason Anello pointed out. concatenation isn't covered yet. I read the OP's code too fast and didn't notice the semicolons that allowed him to make multiple statements on one line. Jason's answer below is probably correct. I'm just leaving mine and the other answers for reference. **
Stormy, you only need to use echo at the beginning of the line. Then use concatenation (using . ) to join your strings with your variable.
$avariable = "foo";
$bvariable = "bar";
echo "some text. this goes in quotes ". $avariable ." ". $bvariable." this is more text added to the end.";
output: some text. this goes in quotes foo bar this is more text added to the end.
I think your confusion might be, because in some of those videos he's inserting php into a bunch of html. so it looks more like this:
<?php
$a = "foo";
$b = 'bar';
?>
<h1>This is HTML </h1>
<p>we are just typing html and whoops here goes some php <?php echo $a; ?> and now we are back to html and wait for it, here goes some more php <?php echo $b; ?> </p>
<p> You can also do php back to back, but that would look weird like this <?php echo $a;?> <?php echo $b; ?>. </p>
Output: This is HTML we are just typing html and whoops here goes some php foo and now we are back to html and wait for it, here goes some more php bar
You can also do php back to back, but that would look weird like this foo bar.
Andrew McCormick
17,730 PointsAndrew McCormick
17,730 PointsThis is correct. I read his code to quickly earlier. I just ran his code through as is, except with the p tags added back and it worked fine.