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

Code Challenge: Switch Statements - showing an error though it is executing the code

this is the code I have written

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

//change to switch statement
switch($role) 
{
  case "admin":
    echo "admin";
    if($role == "admin")
    {
        echo "As an admin, you can add, edit, or delete any post.";
    };  
    break;

  case "editor":
    echo "editors";
    break;

  case "author":
    echo "author";
    break;

  case "subscriber":
    echo "subscriber";
    break;

    default:
      echo "You do not have access to this page. Please contact your administrator.";
      break;
}
Sean T. Unwin
Sean T. Unwin
28,690 Points

I formatted your post for readability.

1 Answer

Sean T. Unwin
Sean T. Unwin
28,690 Points

There is a semi-colon (;) after the if statement in the 'admin' case.

In fact, that if statement is not needed as it is redundant because if the code is executed there the $role value is 'admin' so there is no requirement to check it again.

thanks solved my problem