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

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,860 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:

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