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

The following question is broken: "Check if each student has a GPA of 4.0."

It says I'm getting the incorrect output.

The test output is showing an additional space and "2" character on the end of the output.

It does work fine however separately in work spaces. I have screenshots if you need them!

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 Role.\n";
} else {
  echo "$studentOneName has a GPA of $studentOneGPA.\n";
}

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

?>

1 Answer

Kent Γ…svang
Kent Γ…svang
18,823 Points

There's a couple of small things you should change though. First you are checking wether $studentGPA is identical to 4.0, but you are supposed to check if the GPA is equal to 4, therefore "==" is the correct syntax. This is a minor issue though, but it might be enough to screw up their code for checking the correctness.

Second I think you are supposed to use concatenation in your echo-output. Anyway, I passed the challenge using 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 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;
}

?>

Hope it helped. Good luck.

Thanks for your help Kent. I have since managed to get it to pass another way I still believe the question check needs amending.

Thanks again Kent.