PHP PHP Basics Daily Exercise Program Conditionals

Fred Merilien
Fred Merilien
2,852 Points

Why am I seeing an error telling me that my variables were not set correctly?

When I preview the code in the console, I am seeing the expected result. However, I am seeing an error message. Can someone please enlighten me? What am I missing in the exercise?

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";
}

?>

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,062 Points

Hi Fred Merilien

You've pretty much got it, except for one tiny error. When checking the students' GPAs, you need to be checking for 4.0 which is an Float. In your code, however, you have enclosed the 4 in quotation marks, which now makes it the String 4 instead.

I don't do PHP full-time, but in actuality, your comparison should work in real-life implementation, because your are loosely comparing a string (which would be converted) to a float value, only because of the loose comparison. You can read up on this in the Docs.

But for the case of the Challenge, just change the string 4.0 to be a float (by removing the quotes), and everything else should be good to go.

Nice work! :) :dizzy:

Fred Merilien
Fred Merilien
2,852 Points

Ahh, awesome. Thank you for shining some light on this challenge for me.