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

budoor ayhd
budoor ayhd
1,471 Points

Hello, where the error in this code!

where the error in this code! the Q is : Check if each student has a GPA of 4.0. If the student has a GPA of 4.0, use the student's name variable to display "NAME made the Honor Roll". If not, use the variable to display "NAME has a GPA of GPA".

index.php
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;

$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;

if ( $studentTwoGPA = 4.0 )
{
 echo  "$studentTwoName made the Honor Roll";
}
else {

  echo "$studentTwoName has a GPA of GPA";
}
?>

In the if statement you are assigning with =.

Compare values with == or ===.

Umesh Ravji
Umesh Ravji
42,386 Points

Just to add to the previous comment, you are also missing the value of the GPA variable in the secound echo statement.

5 Answers

Zoltán Rajcsányi
Zoltán Rajcsányi
6,426 Points

The soulution is that:

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

?>

So, I investigated all of the students and criteria... :)

budoor ayhd
budoor ayhd
1,471 Points

Thanks Zoltán Rajcsányi :)

carlos almanzar
carlos almanzar
1,935 Points

why is these '{}' used around the $studentOneName and $studentTwoName?

Zoltán Rajcsányi
Zoltán Rajcsányi
6,426 Points

re: why is these '{}' used around the $studentOneName and $studentTwoName?

I like "${name_of_variable}" full format embeded var in string because:

  • easier recognise that is an embeded variable in string
  • always work, where the normal $varible it doesn't
  • unify my code
budoor ayhd
budoor ayhd
1,471 Points

but still give me error!!

Umesh Ravji
Umesh Ravji
42,386 Points

Could you please post your updated code so someone can see :)

Did you change those 2 things?

Here, like this:

<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;

$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;

if ( $studentTwoGPA == 4.0 ) {
    echo  "$studentTwoName made the Honor Roll";
} else {
    echo "$studentTwoName has a GPA of $studentTwoGPA";
}

This gives me the following message on my local machine:

Treasure made the Honor Roll

If I change $studentTwoGPA to 3.9, I get the message:

Treasure has a GPA of 3.9

Bingo Bongo - working! :)

Oh - the question is asking for student 1, not student 2!

Change the 3 lines in the if statement and it should work...

budoor ayhd
budoor ayhd
1,471 Points

OMG!! the same error

Budoor, you only checked for student two, you have to check for student one also. Hope this helps! :)