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

Mika Laakso
Mika Laakso
4,222 Points

How can I check the student one?

These boolean tasks are squeezing my brain :)

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

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

//Place your code below this comment
if ($studentTwoGPA == 4.0)
{
echo "Treasure made the Honor Roll";
} elseif ($studentOneGPA < 4.0 )
{
echo "Dave has a GPA of 3.8";
}

?>

4 Answers

Hello again!

You are on the right track with the If statement.

However, instead of using the static name in the "ECHO" statement, you should use the variable that stores the name:

<?php
  echo $studentOneName . " made the Honor Roll";

Furthermore, you don't need to use an "ELSE IF" statement, you can just use an "ELSE" statement. Like this:

<?php
else {
  echo $studentOneName . " has a GPA of " . $studentOneGPA;
}

You are really almost there. Just make these adjustments and you should be able to finish the challange.

Mika Laakso
Mika Laakso
4,222 Points
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;

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

//Place your code below this comment
if ($studentTwoGPA == 4.0)
{
echo $studentOneName . " made the Honor Roll";
} elseif ($studentOneGPA < 4.0 )
{
echo $studentOneName . " has a GPA of " . $studentOneGPA;
}
?>

Hi Joao, I put the code like this. But it still doesn't go through the first argument. I tried the else statement, but it gave syntax error.

Hey!

When you check if the $studentTwoGPA equals 4.0, you have to echo the $studentTwoName, not the $studentOneName. Like this:

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

Does that make since? Then, you just have to repeat this code for the StudentOne

Mika Laakso
Mika Laakso
4,222 Points

Thank you, Joao Rosa, now I got it!