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 Daily Exercise Program

Previous Code 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.\n"; } else { echo "$studentOneName has a GPA of GPA.\n"; } if ($studentTwoGPA == 4.0) { echo "$studentTwoName made the Honor Role.\n"; } else { echo "$studentTwoName has a GPA of GPA.\n"; }

?>

Please can someone tell me what is wrong with my code,because when i compile my code it seems to me ok,but i can't complete task because it says that I need to check that $studentTwoGPA is equal to 4.0?

3 Answers

Daniel Gauthier
Daniel Gauthier
15,000 Points

Hey Antonia,

I looked over your code and found where you were going wrong.

I'll post a comparison below to give you a better idea of what went wrong.

First, here is your code, after being formatted:

<?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.\n";
} else {
  echo "$studentOneName has a GPA of GPA.\n";
}

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

?>

The result is a super descriptive error message saying "Bummer! fail".

This is your code, formatted and corrected to pass:

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

?>

There were three, possibly four, errors in your code.

The most major issue was that the challenge wanted you to echo out the line "<student> has a GPA of <GPA>" if the student did not have a GPA of 4.0. In your supplied code, the line would echo "<student> has a GPA of GPA.".

To correct this, the corrected code uses the $studentOneGPA and $studentTwoGPA variables to pull their actual GPA into the echoed statement.

The second issue was trying to use periods at the end of the sentences, which I can completely understand since I do this a lot as well. It just feels right :D

The challenge parser is really finicky about things though, and since we weren't asked to add periods, it will evaluate to a failing attempt.

The corrected code removed the periods.

The third issue is much like the second issue, with the addition of newline escape characters when they were not requested by the challenge. This is another error I've made myself as the code will smash the statements together without them, and this feels wrong.

However, the code editor doesn't feel the same way, so extra characters result in a failed attempt.

The fourth issue may not have been an issue at all, since it's difficult to tell how your code was formatted initially due to how the forums display code that is simply written out in a post, but it is possible you were also failing due to how you structured your if blocks.

Take a look at where the opening and closing braces of your if block is if you continue to experience difficulties, as the parser is really picky about this particular challenge when it comes to where you place the braces.

The above code will work if all else fails, and your code shows that you understand the concepts being taught here, so at this point it's just a matter of providing the code the way the parser wants :D

Good luck with the course!

Daniel Gauthier
Daniel Gauthier
15,000 Points

How to Post Code on the Forums

There are two ways to share your code on the forums here, excluding using external tools from outside of Treehouse.

Method One

The first method is to use a series of three ` (backticks, located at the top left of the keyboard) without any spaces on one line, paste all of your code starting on the second line, then closing the code block with a second series of three backticks. Take a peek at the link for the "Markdown Cheatsheet" located above the "Post Answer" button anytime you're about to post a comment or answer. Using this method, the code will look like this:

```css
(code here)
```

Method 2

The second method is a little more convoluted, but it lets us look at your entire project and make our own copy to try fixing issues. I'll order the steps since it can be a little confusing the first time around:

  1. Open the workspace you're having trouble with.

  2. On the menu bar located to the left of the "Preview Workspace" button is the "Snapshot Workspace" (camera icon), click that.

  3. A popout will appear with another button that says "Take Snapshot", click that.

  4. It should create a new snapshot, which will appear beneath the "Take Snapshot" button in the popout. Click the snapshot you want to share.

  5. The snapshot should open a new browser tab. Highlight the url in the snapshot's browser tab (it should look like this: https://w.trhou.se/duckyj79b1i0 ).

  6. Create your forum post and paste the snapshot's url into the post. Other Treehouse users will be able to open the snapshot, then 'fork' a new copy to check out your code.

Keep in mind that you can only ever have five snapshots, but you can delete them by hovering over the snapshot located below the "Take Snapshot" button in the popout and clicking the trash bin icon.

Good luck!

jough
jough
12,984 Points

why isnt there a way to post questions about exercises on the url of the exercise itself, rather than in the preceding or subsequent lesson??

oh, i thought that i failed everything xD thank you so much for explanation, you are so nice :) i will use snapshot next time :D