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 Arrays and Control Structures PHP Conditionals Switch Statements

Teacher Russell
Teacher Russell
16,873 Points

Confused about the instruction.

I made a mess and can't remember what I even started with. Can I get a clue as to where I'm going? Just a hint. Thanks!

switch.php
<?php
//Available roles: admin, editor, author, subscriber
if (!isset($role)) {
    $role = 'subscriber';
}

//change to switch statement

    switch ($role) {
      case 1 :
        echo 'As an admin, you can add, edit, or delet any post.';
      default:
    echo "You do not have access to this page. Please contact your administrator.";
    }

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Russell,

You are on the right track :thumbsup:

Here's some hints: :)

  • Sometimes PHP doesn't like spaces in certain places. Eg. between switch and the () or the colon after the case.
  • You are checking for a case matching the integer on 1? You should be checking for a case with the string "admin"
  • After each case, there needs to be a break;.

Now here's the weird thing, when I copy/pasted your code and made the corrections, it still threw an error?!? But when I hand type everything in from start into a fresh challenge, it passes. :confused: I compared your code with the corrections to my hand coded one and they are identical, but one won't pass. I don't get it, so I suggest you reset the challenge and give it another go. You are almost there, just add those few corrections in and it should pass.

If you are still having issues, have a look at this past post on this question.

Keep Coding! :) :dizzy:

Teacher Russell
Teacher Russell
16,873 Points

That was a mess and a typo. After a rest, and reading your answer carefully, I got did this and passed. Thank you! <?php //Available roles: admin, editor, author, subscriber if (!isset($role)) { $role = 'subscriber'; }

//change to switch statement switch ($role) { case 'admin' : echo 'As an admin, you can add, edit, or delete any post.'; break; default: echo 'You do not have access to this page. Please contact your administrator.'; break; }