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 trialJacob Anderson
7,888 PointsSyntax error for code challenge.
I keep having a syntax error on line 12 for the echo. I am not sure what I am doing wrong but if anyone could help let me know :).
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;
$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;
//Place your code below this comment
if ($studentTwoGPA == 4.0) {
echo"$studentTwoName made the Honor Roll";
} else ($studentTwoGPA != 4.0) {
echo "$studentTwoName has a $studentTwoGPA GPA";
}
if ($studentOneGPA == 4.0) {
echo"$studentOneName made the Honor Roll";
} else ($studentOneGPA != 4.0) {
echo "$studentOneName has a $studentOneGPA GPA";
}
?>
2 Answers
Bryce Santos
11,157 PointsAlso, make sure to follow the sentence structures closely. You need to make sure it says exactly that studentOneName has a GPA of studentOneGPA as opposed to how you had "studentOneName has a "studentOneGPA GPA" or it'll mark it incorrect. Here's the correct code to help you out.
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;
$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;
//Place your code below this comment
if ($studentTwoGPA == 4.0) {
echo "$studentTwoName made the Honor Roll";
} else{
echo "$studentTwoName has a GPA of $studentTwoGPA";
}
if ($studentOneGPA == 4.0) {
echo "$studentOneName made the Honor Roll";
} else{
echo "$studentOneName has a GPA of $studentOneGPA";
}
?>
Bryce Santos
11,157 PointsElse will always be everything ELSE that's NOT in the original if or else if statement, so the != comparison isn't needed.