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

Iulian Mirzac
Iulian Mirzac
3,083 Points

Check if each student has a GPA of 4.0.

Why don't i get the pass for this test ? The output seems correct, the values on different lines, and values have spaces beside 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 HonorRoll' . "\n";
}
  else {

  echo $studentOneName . ' has a GPA of ' . $studentOneGPA . "\n";
  }

if ($studentTwoGPA == 4.0) {
  echo $studentTwoName . ' made the HonorRoll' . "\n";
}
  else {

  echo $studentTwoName . ' has a GPA of ' . $studentTwoGPA . "\n";
  }


?>
Iulian Mirzac
Iulian Mirzac
3,083 Points

Fixed by correcting HonnorRoll with Honnor Roll.

3 Answers

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

I think the problem is in your echo lines.

You wrote HonorRoll' . "\n" which should be Honor Roll and the "\n" might make it fail too because the challenges sometimes are very strict about what to do, and when you add "\n" without being told to then it might make you fail.

This line fails too: has a GPA of ' . $studentOneGPA . "\n" because it should be has a GPA of (insert GPA here) GPA and same thing for the "\n" (not told to make it).

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

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

//Place your code below this comment
if ($studentOneGPA == 4.0) {
  // noticed how to use variables directly inside strings by using double quotes
  echo "$studentOneName made the Honor Roll";
} else {
  echo "$studentOneName has a GPA of $studentOneGPA GPA";
}

if ($studentTwoGPA == 4.0) {
  echo "$studentTwoName made the Honor Roll";
} else {
  echo "$studentTwoName has a GPA of $studentTwoGPA GPA";
}
?>
SP Prabhakar
SP Prabhakar
11,429 Points

kindly solve it this way-->> 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; }

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points
<?php

// this will make the challenge fail
echo $studentOneName. " has a GPA of ".$studentOneGPA;
echo $studentTwoName. " has a GPA of ".$studentTwoGPA;

// should be like this (if using concatination)
echo $studentOneName . " has a GPA of " . $studentOneGPA . " GPA";
echo $studentTwoName . " has a GPA of " . $studentTwoGPA . " GPA";

?>
Iulian Mirzac
Iulian Mirzac
3,083 Points

As Henrik pointed it out I wrote HonorRoll instead of Honor Roll. :) That was the problem. Thanks guys for the quiick response i didn't thought somebody will answer so fast.

Althogh the problem can be solved in a numberous ways, i am glad it's just a small error.