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 trialAngelie Sioson
Front End Web Development Techdegree Student 2,996 Pointscorrect answer please???
It says i don't have the correct default blah blah.
<?php
//Available roles: admin, editor, author, subscriber
if (!isset($role)) {
$role = 'editor';
}
//change to switch statement
switch ($role = 'admin') {
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;
}
4 Answers
Amber Stevens
Treehouse Project ReviewerAngelie, when I copied and pasted James code into the code challenge it passed - for both part 1 and part 2... In your original code above it looks like you were on part one of the challenge and aside from needing the quotation marks around 'admin' you were also just missing a comma right after the words "as an admin[comma here]...." But the 2nd snippet of code that James showed you passes both parts of the challenge....
jamesjones21
9,260 Pointsyou need to put the $role variable in the parenthesis without the the equals 'admin' and then for each case the switch statement tests it will output the correct option. P.S do check your case for admin, you are forgetting the single / double quotes around the wording admin.
<?php
//Available roles: admin, editor, author, subscriber
if (!isset($role)) {
$role = 'editor';
}
//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;
}
Angelie Sioson
Front End Web Development Techdegree Student 2,996 PointsHi James,
The answer you provided is still not accepted. The error:
"Bummer: I do not see the correct output for admin. Did you leave off a "break"?
jamesjones21
9,260 PointsAngelie Sioson can you provide me with your code? But going by the error message you are are missing the break keyword after the first check. Each case is checked against the variable $role, if it matches, it then outputs the string and it will need to break otherwise it will carry on.
Your code should look like this, but by all means use it as a reference guide to correct your errors.
<?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 '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.";
}
Angelie Sioson
Front End Web Development Techdegree Student 2,996 PointsThe above posted code is my answer.
The code you provided is still not accepted on my end. It is saying I don't have the correct default message. I even copied and pasted your exact code but it is still wrong. Could it be a bug... hmm..
corbinb
2,655 PointsFirst, you want the $role variable by itself in the parenthesis. Second, make sure what the case value is comparing the variable to is in parenthesis since this is a string.
<?php
//Task 1
//Available roles: admin, editor, author, subscriber
if (!isset($role)) {
$role = 'subscriber';
}
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;
}
?>