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 trialEvan MacAlpine
7,173 PointsTask 1 of 1 not working in PHP basics conditionals code challenge
I can't make this code pass. It seems as though the challenge can see my else blocks as it keeps on giving me error messages that say, "Don't forget to add the else blocks".
<?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 Roll";
}
else {
echo"$studentOneName has a GPA of $studentOneGPA";
}
if($studentTwoGPA === 4.0){
echo"$studentTwoName made the Honor Roll";
}
else {
echo"$studentTwoName has a GPA of $studentTwoGPA";
}
?>
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Evan,
For the most part you are correct. it's just a bit of a syntax issue that is happening. PHP likes the opening else
to come on the same line and right after the closing brace of the if
statement. PHP Docs.
So just move those around and your good to go.
Good job on using the double quotes to evaluate the variable values in the strings. I've seen many questions regarding this challenge and everyone always uses concatenation. So, awesome use of being DRY!
<?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 Roll";
} else {
echo"$studentOneName has a GPA of $studentOneGPA";
}
if($studentTwoGPA === 4.0){
echo"$studentTwoName made the Honor Roll";
} else {
echo"$studentTwoName has a GPA of $studentTwoGPA";
}
?>
Keep Coding! :)
Evan MacAlpine
7,173 PointsEvan MacAlpine
7,173 PointsThanks Jason! You're right. I'm used to Javascript if/else statements :). Been banging my head against the wall on this one for a bit so the help is appreciated!