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 trialshubhamkt
11,675 Pointsbummer! I dont see the break..
for case "admin" it is showing that the break has been missed. but the code works in the preview. Any thoughts
<?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;
case 'editor':
echo " You do not have access to this page. Please contact your administrator.";
break;
case 'author':
echo " You do not have access to this page. Please contact your administrator.";
break;
case 'subscriber':
echo "You do not have access to this page. Please contact your administrator.";
break;
default:
echo "You do not have access to this page. Please contact your administrator.";
break;
}
2 Answers
Craig Watson
27,930 PointsI have had a blast of the code challenge and the below should get you going:
<?php
// Add this as your switch, NOTE - no space before the "AS" in the admin case...
switch ($role) {
case 'admin':
echo "As an admin, you can add, edit, or delete any post.";
break;
case 'editor':
echo "As an editor, you can add or edit any post, and delete your own posts.";
break;
case 'author':
echo "As an author, you can add, edit, or delete your own post.";
break;
default:
echo "You do not have access to this page. Please contact your administrator.";
}
Hope this helps Craig :)
Chris Shaw
26,676 PointsI recommend you read the question for the challenge tasks again, the text for your admin
case has a space at the start of the string that isn't needed, you appear to have a subscriber
case that isn't part of the challenge and have included the wrong text for editor
& author
.
Aside from that, your code is structurally correct.