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 trialCorey Lyons
24,684 PointsPHP conditionals challenge
It is saying make sure you add the else blocks in the error message. I'm stuck on this and its frustrating. Any help would be appreciated.
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;
$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;
//Place your code below this comment
if ($studentOneGPA === 4.0) {
echo $studentOneName . " " . 'made the Honor Roll';
} elseif ($studentTwoGPA === 4.0) {
echo $studentTwoName . " " . 'made the Honor Roll';
} elseif ($studentOneGPA === 3.8) {
echo $studentOneName . " " . 'has a GPA of GPA';
} elseif ($studentTwoGPA === 3.8) {
echo $studentTwoName . " " . 'has a GPA of GPA';
}
?>
3 Answers
Corey Lyons
24,684 PointsI figured it out just restarted the challenge
if ($studentOneGPA === 4.0) { echo "$studentOneName made the Honor Roll"; } else { echo "$studentOneName has a GPA of $studentOneGPA"; }
Alexander Davison
65,469 PointsWhen the challenge says "has a GPA of GPA" it meant something like "has a GPA of 10"
Corey Lyons
24,684 PointsNow I get unexpected end of file
$studentOneName = 'Dave';
$studentOneGPA = 3.8;
$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;
//Place your code below this comment
//check first student
if ($studentOneGPA == 4.0) {
echo $studentOneName . " made the Honor Roll";
} else {
echo $studentOneName . " has a GPA of " . $studentOneGPA;
//check second student
if ($studentTwoGPA == 4.0) {
echo $studentTwoName . " made the Honor Roll";
} else {
echo $studentTwoName . " has a GPA of " . $studentTwoGPA;
}
```?>
Adam Vasik
11,702 PointsAt the bottom of the code, there should be "?>" instead of "```?>". I struggle with this challenge myself since I mada a code that works just fine. And in the description is said if it's not equal to "4.0" but unfortunately, it wants you to check if it is equal and then use the else statement. But your second code in the comment looks like it should work.
Brian Cronin
1,390 PointsBrian Cronin
1,390 PointsJust completed it. Don't forget second half If ($studentTwoGPA===4.0) etc