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] Can't pass code challange

PHP Basic - Conditionals

I don't understand why it wont pass. I'm sure it's inefficient, messy and could be better written. But.

Bummer! Use the variables to display the message

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

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

//Place your code below this comment
$GPA = "has a GPA of";
$HonorRole = "made the Honor Role";

if ($studentOneGPA === 4.0) {
  echo "$studentOneName $HonorRole";
} else {
  echo "$studentOneName $GPA $studentOneGPA";
}
if ($studentTwoGPA === 4.0) {
  echo "$studentTwoName $HonorRole";
} else {
  echo "$studentTwoName $GPA $studentTwoGPA";
}
?>

Thanks Darrell, I have taking the custom variables out and thrown in "NAME made the Honor Role" and "NAME has a GPA of GPA". But it is still failing. I've never had troubles understanding the questions, but this is confusing. I'm moving on.

3 Answers

Darrell Conklin
seal-mask
.a{fill-rule:evenodd;}techdegree
Darrell Conklin
Python Development Techdegree Student 22,110 Points

If you copy paste the code below I can guarantee you will pass. It also didn't like the identical operator it wanted the equality one. A little buggy if you ask me.

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";
}
Eric Jones
Eric Jones
24,588 Points

Be sure to use the appropriate spelling of Honor Roll

Chris Adamson
Chris Adamson
132,143 Points

It looks like your attempting shell (bash) string interpolation. Normally, you could make your code work using the . (dot) concatenation operator. For this exercise, it doesn't need extra variables as you declared.

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

Thanks guys.