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

Nick Tsamis
PLUS
Nick Tsamis
Courses Plus Student 4,267 Points

the code runs in my terminal why incorrect Output?

/Place your code below this comment

if($studentOneGPA == 4.0){

echo "$studentOneName made the Honor Roll ";

}else{

echo "$studentOneName has a GPA of GPA ";

}

if($studentTwoGPA == 4.0){

echo "$studentTwoName made the Honor Roll ";

}else{

echo "$studentTwoName has a GPA of GPA ";

}

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 GPA ";

}

if($studentTwoGPA == 4.0){

  echo "$studentTwoName made the Honor Roll ";

}else{

  echo "$studentTwoName has a GPA of GPA ";

}







?>

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi Nick.

First, all your echo output has an extra space at the end, they will cause mismatch error w/ the test cases used by the grader.

Secondly, "NAME has a GPA of GPA", for the 2nd GPA in the echo message, the challenge actually wants you to replace it w/ the student GPA variable $. I admit the wording here is very confusing, and took me a while to figure that out too.

So the corrected version of your code looks like this

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

}
?>

hope it helps.