Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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/