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 trial

PHP PHP Basics Daily Exercise Program Conditionals

Corey Lyons
Corey Lyons
24,684 Points

PHP 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.

index.php
<?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
Corey Lyons
24,684 Points

I 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"; }

Just completed it. Don't forget second half If ($studentTwoGPA===4.0) etc

When the challenge says "has a GPA of GPA" it meant something like "has a GPA of 10"

Corey Lyons
Corey Lyons
24,684 Points

Now 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
Adam Vasik
11,702 Points

At 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.