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

Andrew Dovganyuk
Andrew Dovganyuk
10,633 Points

Hi guys i completely confuse and lost :) Any one please help?!

Help to understand how to write it!

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

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

//Place your code below this comment
var_dump ($studentOneGPA == 4.0);
if ($studentTwoGPA == 4.0) {
  echo "$studentTwoName made the Honor Roll";
}
else ($studentOneGPA == 4.0) {
  echo "$studentOneName has a GPA of GPA";
}

?>

1 Answer

Joe Scotto
Joe Scotto
8,282 Points

I'm going to break your code down into some smaller chunks so it's easier for you to understand.

First, var_dump is used to dump the contents of a variable and to my knowledge cannot be used for evaluation. Change your var dump to the following:

var_dump ($studentOneGPA);

Second, you're using an if else improperly. When using just an else statement, you cannot provide any parameters, only an else if can contain comparison. Change your if else to the following:

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

The final issue here is that you're essentially checking for the same thing in both the initial condition and the else if condition. You should always check for different values when running an if else Change it to the following:

// Only gets run if the GPA is equal to 4.0 otherwise the else if is run if the GPA is below 4.0
if ($studentTwoGPA == 4.0) {
  echo "$studentTwoName made the Honor Roll";
} else if ($studentOneGPA < 4.0) {
  echo "$studentOneName has a GPA of GPA";
}