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 trialJonas Støvring
5,229 PointsI can't seem to write this piece of code right :S PHP arrays and Control statement. Last Challenge task 1 of 2..
So far I tried this, but it wont accept it :D Probably because it's wrong :D :D
<?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; } ?>
<?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;
}
?>
4 Answers
João Rosa
2,629 PointsHey Jonas!
You have two errors in your code. First in your "case", you are using a variable that doesn't exist, instead of using the string "admin":
<?php
case "admin":
?>
Second, your switch condition is wrong. It should be:
<?php
switch ($role == 'admin') {
?>
This second point is not very explicit in the challange, I figured it out by trying.
Hope it helps!
Jonas Støvring
5,229 Pointsswitch ($role != 'admin') { default: echo "You do not have access to this page. Please contact your administrator."; break;} switch ($role == 'admin'){ case admin: echo "As an admin, you can add, edit, or delete any post."; break;
Tried this instead to try something of what you recommended.
Jonas Støvring
5,229 Pointsif($studentOneGPA ==4.0){ echo "$studentOneName made the Honor Roll";} else{ echo "$studentOneName has a GPA of $studentOneGPA";}
if($studentTwoGPA ==4.0){ echo "$studentTwoName made the Honor Roll"; ?>
I tried to do it.. But know it tells me a Syntax error on line 17.. Wich is my php end tag ?>
João Rosa
2,629 PointsYou didn't closed the 2nd "if" statement.