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

benjamin sanchez
benjamin sanchez
6,101 Points

PHP-basics-2 - $StudentOneGPA & $StudentTwoGPA - I don't understand what i'm doing wrong - the output seems alright.

For some reason it keeps telling me I have to display is 'using name variables' or something like that - i'm trying to make the $studentOneName variable = the output, but it still doesn't work! Any advice would be appreciated :)!

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

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

//Place your code below this comment

if($studentOneGPA === 4.0){
  $studentOneName = "$studentOneName made the Honor Role";
} else {
  $studentOneName = "$studentOneName has a GPA of $studentOneGPA";
}

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

echo $studentOneName;
echo $studentTwoName;




?>

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! The biggest problem here is that you're overwriting their variables. You may not do that. Even if functional, it will cause the challenge to fail. So this line here:

 $studentOneName = "$studentOneName made the Honor Role";

should be a direct echo

echo "$studentOneName made the Honor Role";

Try it again without writing over their variable values. Hope this helps! :sparkles:

benjamin sanchez
benjamin sanchez
6,101 Points

Thank you for your reply - I tried to do as you said - here is a snippet of the code I used

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

But I keep getting this -> Bummer! Use the variables to display the message

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

benjamin sanchez you're correct! I forgot to point that out. For whatever reason, the triple equals will cause the challenge to fail (as will another bug). I sent in a bug report on Friday, so I hope it's fixed soon! I posted a working solution that you can view here.

Hope this helps! :sparkles:

benjamin sanchez
benjamin sanchez
6,101 Points

Thank you :D ! It was the '===' I too hope it is fixed soon. See you around o/