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 PHP Basics Daily Exercise Program Daily Exercise Program

Jason Brown
Jason Brown
9,626 Points

Program always returns today's date, no matter how many times I change the $day variable ...

I can't get this program to return anything but today's date. Please help! : "" <?php // Store each exercise in a string variable. $exercise1 = "this"; $exercise2 = "isnt"; $exercise3 = "working"; $exercise4 = "i"; $exercise5 = "want"; $exercise6 = "it"; $exercise7 = "to work";

$day = date('N');

if ($day == 1) { echo $exercise1; } elseif ($day == 2) { echo $exercise2; } elseif ($day == 3) { echo $exercise3; } elseif ($day == 4) { echo $exercise4; } elseif ($day == 5) { echo $exercise5; } elseif ($day == 6) { echo $exercise6; } else { echo $exercise7; } $day = 3; $day = date(2);

// create a variable containing the day of the week. // Use if statement to test for the day of the week. // display corresponding exercise string.

$day = 1; $day = 1; ?> ""

1 Answer

Hey Jason, You need to move your different $day declarations up above the if block, because right now the only $day value being fed into all your if statements is the one above it, which is $day = date('N');. If you moved your $day = 3 or $day = 1 statements up so they're just underneath your $day = date('N') statement, you'd echo different outputs as desired.

Hope this helps!

Jason Brown
Jason Brown
9,626 Points

Gah! Of course! I wouldn't do this if I was actually writing a program ... I just wasn't thinking about that because I was fooling around in workspaces. Ohhh boy ... Thanks so much for your response. A valuable lesson learned, either way. Thanks again.