Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,316 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,101 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.