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 trialNeiv Schwartz
1,537 PointsCode 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;
}
?>
Tim Knight
28,888 PointsNeiv, 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?
Neiv Schwartz
1,537 PointsThanks Tim!
Here is the link to the objective: https://teamtreehouse.com/library/php-basics-2/daily-exercise-program/conditionals
2 Answers
Tim Knight
28,888 PointsNeiv 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;
}
?>
Neiv Schwartz
1,537 PointsThank you. It seems that I needed to move "else" to one line before. It works now.
Darrell Conklin
Python Development Techdegree Student 22,377 PointsIt seems to be an issue with the way the code is formatted.
Here is an example.
I did the same thing to your code and it passed.
Neiv Schwartz
1,537 PointsThanks Darrell. I moved "else" to the line above it and it works now.
Neiv Schwartz
1,537 PointsNeiv Schwartz
1,537 PointsIt 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.