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 trialYoga Darmawan
1,748 PointsPlease help on the Switch Statement Quiz
Please help,
I keep getting "i do not see the default message correctly" and i think my code is right
<?php
//Available roles: admin, editor, author, subscriber
if (!isset($role)) {
$role = 'subscriber';
}
//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;
}
?>
3 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Yoga,
Your problem is with the switch statement switch ($role != 'admin') {
You only need to do switch ($role)
You put in the variable you want to check and then its value will be compared against each case statement.
Andy Hughes
10,049 PointsYou're almost correct. I tested a few things with this challenge and found that if I failed it, 90% of the time it was not because my code did not produce the correct output, but because of grammar and spelling.
One time I added an additional "e" to "edit" and it failed, even though the code was correct. Another time I left the period (full stop) off of the end of one of the echo statements and it also failed.
This challenge is very very fussy about the spelling and punctuation so if you're struggling, firstly check each echo line word by word for the spelling. Then check your periods, commas and speech marks. If all of that is spot on then it is likely to be a code issue. Chances are though, if you've checked it and know the code is ok, you should pass.
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.";
}
Yoga Darmawan
1,748 PointsHi everyone, thanks for the answer.
I haven't be able to test it out again, been busy with work this week. I'll be sure to test your code out and will give feedback after it.
Thanks. Yoga
sayedshahidi
9,158 Pointssayedshahidi
9,158 PointsYour code isn't right. Try this and it should work.
I hope this can help.