Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Basics Daily Exercise Program Conditionals

Fred Merilien
Fred Merilien
3,367 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,546 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
3,367 Points

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