Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Creating the Menu and Footer Variables and Conditionals

task 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

Hi 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.

Andrew McCormick
Andrew McCormick
17,729 Points

This 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.

Richard Duncan
Richard Duncan
5,568 Points

echo "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.

Hi 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
Andrew McCormick
17,729 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.