PHP PHP Arrays and Control Structures PHP Conditionals Switch Statements

Megan Stachnick
Megan Stachnick
1,806 Points

It keeps saying my default output is incorrect, help?

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

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

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

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

1 Answer

jonathanbarrios
STAFF
jonathanbarrios
Treehouse Teacher

👋 Hello Megan Stachnick,

The switch statement should be $role to check against each case:

<?php
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;
}

I hope this is useful and happy coding! 🙌