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

Code Challenge (PHP Track)

The code challenge is as follows: Check if each student has a GPA of 4.0. If the student has a GPA of 4.0, use the students name variable to display "NAME made the Honor Role". If not, use the variable to display "NAME has a GPA of GPA".

The challenge showed an error saying that I must add in the else blocks. Can you please check my code to see where I have gone wrong?

Here is the code I entered along with the code provided by the challenge:

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

?>

It seems that the comment box above smushed my code together, but it is all still there. I would post this directly from the code challenge, but the help button is not working at the moment.

Tim Knight
Tim Knight
28,888 Points

Neiv, I just formatted your code for you to make it easier to see. Feel free to edit your question to see how I did it. Can you post a link to the specific quiz you're currently on that's asking you this question?

2 Answers

Tim Knight
Tim Knight
28,888 Points

Neiv your code looks good to me. I just used this exact code to pass that objective. Double check your spacing and compare yours with this code which should be same from what I can tell.

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

Thank you. It seems that I needed to move "else" to one line before. It works now.

Thanks Darrell. I moved "else" to the line above it and it works now.