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

if / else compare two variabels

I can't figure it out how I should do when I have four different variabels to work with in only one if/else statement.

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

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

if($studentOneGPA == "4.0"){
var_dump($studentOneName . "made the Honor Roll");
}elseif{
  var_dump($studentOneName . "has a GPA of" . $studentOneGPA);
}
  elseif($studentTwoGPA == "4.0"){
  var_dump($studentTwoName . "made the Honor Roll");
}else { var_dump($studentTwoName . "has a GPA of" . $studentTwoGPA);
}


//Place your code below this comment

?>

2 Answers

calp
calp
10,317 Points

Instead of using var_dump you should be using echo. Also, on your first if statement instead of having an else you have an elseif with no condition. To complete this challenge you need two if else statements to check the students GPA and echo out something accordingly.

if ($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";
} else {
  echo $studentTwoName . " has a GPA of " . $studentOneGPA;
}
Stuart Wright
Stuart Wright
41,120 Points

You actually don't need to use elseif at all for this. You just need two separate if/else blocks - the first one to print the appropriate message for student one, then repeat the same code but for student two. You also shouldn't be using var_dump to display the output (that's just used for debugging purposes to show the programmer what's contained in the variable) - you should use echo instead.

Hope that helps, let me know if you need any more hints.