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

Undefined variable

I keep getting Undefined variable: StudentOneGPA. Check your spelling.

How is that?

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  has a GPA of $studentOneGPA";
}else{
   echo "$studentTwoName  made the honor Roll";
}
?>

2 Answers

Look at the variable in your conditional. You have an extra capitalized letter ($student vs $Student)

This is the QUESTION

Check if each student has a GPA of 4.0. If the student has a GPA of 4.0, use the student name variable to replace NAME when displaying the following line: NAME made the Honor Roll If the students GPA is not equal to 4.0, use the student name variable to replace NAME AND the student GPA variable to replace STUDENT GPA when displaying the following line: NAME has a GPA of STUDENT GPA

===

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

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

//Place your code below this comment
if ($studentOneGPA = 4.0){
  echo "$studentOneName  has a GPA of $studentOneGPA";
}else
  {
   echo "$studentTwoName  made the honor Roll";
}
?>  {
   echo "$studentTwoName  made the honor Roll";
}

AND NOW I am getting this ERROR: You need to check that $studentOneGPA is equal to 4.0

How do I fix this. Am totally lost

There are a few other issues with your code that is keeping it from passing. Your conditional is backwards in the examples provided (you're checking if it's 4.0 and if it evaluates to true echoing "Dave has a GPA of 3.8" instead of "Dave made the Honor Roll"). The last of which is your conditional compares $studentOneGPA to the desired value but the else statement deals with $studentTwoName. You should have two separate conditionals, one addressing each student.

Additionally in the second snippet your conditional is using a single = sign so instead of comparing the variable to a desired GPA you're assigning the variable to the desired GPA so you're making it 4.0 instead of 3.8 in this case.

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

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

//Place your code below this comment

// Note: the breaks are added for convenience when previewing code, 
// otherwise the two statements run together on the same line
if ($studentOneGPA == 4.0)
{
  echo "{$studentOneName} made the Honor Roll<br/>";
}
else
{
  echo "{$studentOneName} has a GPA of {$studentOneGPA}<br/>";
}

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