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

Gary Beardsley
Gary Beardsley
1,403 Points

Am I supposed to do an if/else for both variable names? I tried to append the sentence to the name variable,didn't work.

I tried to append the name variable to the sentence required previously but it didn't work. I'm not sure how I am supposed to answer this correctly. In the way I've done it this time I tried to make the $studentOneName = the string required because it says change the variable to display "NAME made 4.0 GPA", not sure what I'm doing incorrectly. I put the alternative version in the comment block at the bottom.

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

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

//Place your code below this comment
if($studentOneGPA == 4.0) {
  $studentOneName = "Dave made the Honor Roll\n";
  echo $studentOneName;
} else {
  $studentOneName = "Dave has a GPA of $studentOneGPA\n";
  echo $studentOneName;
}

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

/*
alternatively:

$studentOneName = 'Dave';
$studentOneGPA = 3.8;

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

if($studentOneGPA == 4.0) {
  echo $studentOneName . "made the Honor Roll\n";
} else {
  echo $studentOneName . " has a GPA of " . $studentOneGPA . "\n";
}

if($studentTwoGPA == 4.0) {
  $studentTwoName = "Treasure made the Honor Roll\n";
  echo $studentTwoName;
} else {
  $studentTwoName = "Treasure has a GPA of $studentTwoGPA\n";
  echo $studentTwoName;
}
*/

?>

1 Answer

Justin Kraft
Justin Kraft
26,327 Points

Hi Gary,

Your first if/else block in the commented alternative section you have posted is the correct format that is looked for. When I checked the assignment I initially left of the new line characters and it was accepted so I'm not sure if it will accept it with them or not. If you repeat the below for the second student you should be able to progress.

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