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 trialDaniel H. Kim
5,333 PointsI am stuck in the PHP Basic 2 quiz and I try answering it, but can't seem to find the right answer.
<?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 GPA"; } if ($studentTwoGPA == 4.0) { echo $studentTwoName ." made the Honor Roll"; } else { echo $studentTwoName ." has a GPA of GPA"; } ?>
What am I doing wrong here? Am I missing "" or ' '?
<?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";
}
if ($studentTwoGPA == 4.0) {
echo "$studentTwoName made the Honor Roll";
}
elseif ($studentOneGPA != 4.0) {
echo "$studentOneName has a GPA of GPA";
}
else {
echo "$studentTwoName has a GPA of GPA";
}
?>
2 Answers
Daniel Stopka
13,520 PointsHi Daniel :)
I do recommend splitting two students into two separate if statement conditions...
You tested if $studentOneGPA == 4.0, that's right, after that you don't need to write 'else if' statement, just simple else - which means, if first condition is false, then a code in else section will pass...
Last thing, do not forget to pass variables inside echo with dolar sign $GPA
Give it a try, if something write...
Daniel H. Kim
5,333 PointsOh... :) Hi Daniel Stopka
Thanks for the reply. I changed the GPA to $GPA and it was fixed. It also asked me for the proper number of the GPA.
I think it was bit awkward that I didn't understand this simple thing.. But I am getting used to the PHP syntex now and getting the hang of it.
Thanks for the feedback! :)