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

PHP

Issues with echo command on a task

I have the task "Use the date function to add todays date to the display message in the following format: full month, day of the month with leading 0, comma and 4 digit year. Example: Today is July 04, 2016"

upon writing my code:

<?php
echo 'Today is ' . "$date" ;
//Place your code below this comment
$date = date("F d, Y");
?>

It displays properly and works, but when submitting the task, I get the error " Bummer! Looks like you forgot the echo command Restart " and this happens regardless if I alter the echo to be bellow the declared variable $date or not. Please advice further

Moderator edited: markdown was added to the question to properly render the code. Please see the Markdown Cheatsheet link at the bottom of the "Add an Answer" section for tips on how to post code to the Community.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again, loan! When it says add your code below this comment, it means that you are not to alter the line of code before that. It's important in these challenges to try not to do anything the challenge doesn't explicitly ask for. Even if functional, it can cause the challenge to fail.

The challenge did not ask for a new variable to be created. All it's looking for here is an additional echo statement. Remember the \n (new line) character we covered in your previous question? It's missing here. This means that even though it's a new echo statement it will come immediately after the preceding one and not on a separate line.

Here is the line it's looking for:

echo date("F d, Y");

Hope this helps! :sparkles:

Understood. But this also occurs if I use this code:

<?php echo 'Today is '; //Place your code below this comment

$date = date("F d, Y"); echo "$date" ?>

And it is displaying as instructed "Today is January 05, 2017" As for the \n should I use it here as well? Because I am not sure that there it should be implemented here?

Thank you for the answer I understood and it all went well!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

No, you don't need the new line. However, you are still doing something that the challenge hasn't asked for. You are implementing a new variable and echoing out the value. But what I believe the challenge is testing is the formatting string inside the date function. But now it can't find it because you've assigned it to a variable. Also, your code is missing a semicolon at the end.

The end code should look like this:

<?php
echo 'Today is ' ;
//Place your code below this comment
echo date("F d, Y");
?>

As a side note, please review the Markdown Cheatsheet to learn how to properly format your code for posting to the Community.