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

how is this not correct? why is the editor telling me not to forget my else blocks?

I am really frustrated with the code challenges on the PHP basics. Even when code is valid it never likes it. And the suggestions about what is wrong is usually off and not helpful to what it actually wants you to do.

OBJECTIVE: display honor roll for gpa of 4.0. for less, display the student name and gpa.

<?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 Role."; } else{ echo "$studentOneName has a GPA of $studentOneGPA."; }

if ($studentTwoGPA === 4.0){ echo "$studentTwoName made the Honor Role."; } else{ echo "$studentTwoName has a GPA of $studentTwoGPA."; } ?>

OUTPUT: Dave has a GPA of 3.8.Treasure made the Honor Role.

index.php
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;

$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;

//Place your code below this comment

?>
Mohamed Mathari
Mohamed Mathari
1,251 Points

Can you please put your code inside a wrapper so we can correctly check and help. Thanks!

1 Answer

Mohamed Mathari
Mohamed Mathari
1,251 Points

Your code should look like the following order;

// set an if statement to set IS EQUAL (==) 4.0 
// echo the student name + made the Honor Role
// if this is not the case, then echo something else
// studentname has a GPA of ......
// Basically we have to bind the variable and text like $studentOneName . ' made the Honor Role';

if ($studentOneGPA == 4.0) {
  echo $studentOneName . " made the Honor Role";
} else {
  echo $studentOneName .  " has a GPA of " . $studentOneGPA;
}

Try to do the other one by yourself.