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

Donald Mak
Donald Mak
1,603 Points

How to check whether GPA is equal to 4.0? I used this logic: If ($studentOneGPA==4.0)

The system said I need to check if GPA equal to 4.0 but I have done that already with my code. Haven't I?

index.php
<?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 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 $studentTwoGPA";
     }
?>

1 Answer

Michael Hulet
Michael Hulet
47,913 Points

PHP is case-sensitive, which means that you have to type its keywords exactly, and it matters if its letters are capital or lowercase. In both places it's written, the "I" in if is capitalized in your code, but the proper keyword is all lowercase. Furthermore, I believe that you'll also have to use string concatenation if you want the value of the variable pasted into your string instead of the variable name. For example:

<?php
$studentName = "Michael"
echo "My name is $studentName"; // echos "My name is $studentName"
echo "My name is " . $studentName; // echos "My name is Michael"
?>
Donald Mak
Donald Mak
1,603 Points

Thanks Mike I think you've solved my problem!