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 trialMicah Walton
4,674 PointsQuiz wont accept what should be the right answer.
Once again the quiz is being super picky I guess in ways that make it hard to pass these things. Haven't had any of this trouble except on the php quizes.
Anyway the quiz says "Bummer! I do not see the correct default output."
I have triple checked. I have not changed the default output. When I test it, the answer comes out right. So I'm not sure what the quiz wants.
<?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;
}
1 Answer
andren
28,558 PointsThere are two issues in your solution:
The word
admin
should be enclosed in quote marks since it is a string. In most languages not doing so would produce a fatal error. In PHP it is technically ok to leave them off because PHP is one of the very few languages that automatically converts unknown words into strings, but it is considered an extremely bad practice to do so. Since it makes it hard to distinguish between strings and variables while reading the code.You are missing a period at the end of the first string.
If you fix those issues like this:
<?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;
}
Then your code will pass the task.
Micah Walton
4,674 PointsMicah Walton
4,674 PointsOk thank you.