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

Victoria Loisi
Victoria Loisi
7,070 Points

Check if each student has a GPA of 4.0: The preview shows the correct output, but I still get error messages!

I don't know, maybe I'm lost in translation (my mother's tongue language is spanish after all), but this is the third exercise in a row where I get error messages, when the output is correct.

This is what I need to do: Check if each student has a GPA of 4.0. If the student has a GPA of 4.0, use the students name variable to display "NAME made the Honor Role". If not, use the variable to display "NAME has a GPA of GPA".

This is what I do:

$studentOneName = 'Dave';
$studentOneGPA = 3.8;
$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;
if($studentOneGPA >= 4.0) {
 echo "$studentOneName made the Honor Role";
} else {
  echo "$studentOneName has a GPA of $studentOneGPA";
}
if($studentTwoGPA >= 4.0) {
 echo "$studentTwoName made the Honor Role";
} else {
  echo "$studentTwoName has a GPA of $studentTwoGPA";
}

I get this error: Bummer! You need to check that $studentOneGPA is equal to 4.0.

Now, my output is correct:

Dave has a GPA of 3.8 Treasure made the Honor Role

I've tried adding \n at the end of every line.

I've tried changing:

if($studentOneGPA >= 4.0) {

to:

if($studentOneGPA = 4.0) {

I still get the error. Even when the preview is correct. What am I doing wrong?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You started by checking if the GPA is greater than or equal to 4.0. It only wants it if it's exactly equal to 4.0. When you changed the equal sign the second time, you used the single equals. This is an assignment operator. Now, in theory you could use either the double equals or the triple equals, but there's currently a bug in this challenge that will prevent it from passing if you use the identical operator (triple equals). I have posted a solution here that will work. And I've also submitted a bug report :smiley:

Take a look here: https://teamtreehouse.com/community/-check-if-each-student-has-a-gpa-of-40-if-the-student-has-a-gpa-of-40-use-the-students-name-variable-to-display-na

Hope this helps! :sparkles:

Victoria Loisi
Victoria Loisi
7,070 Points

It did help, actually. Many thanks, you were right!!