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 trialSasa Sanjic
963 PointsQuiz with task to use three conditional statements
Hi guys
I made the code which is working in the console. I've tested all three conditions. But quiz will not pass me further. Where did I make mistake?
TASK = Check if each student has a GPA of 4.0. If the student has a GPA of 4.0, use the student's name variable to display "NAME made the Honor Roll". If not, use the variable to display "NAME has a GPA of GPA".
<?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.');
} elseif ($studentTwoGPA == 4.0) {
echo ("$studentTwoName" . ' made the Honor Roll.');
} else {
echo ("$studentOneName" . ' has a ' . "$studentOneGPA" . " of " . "$studentTwoGPA");
}
?>
3 Answers
Bapi Roy
14,237 Pointschange echo ("$studentOneName" . ' made the Honor Roll.');
to
echo $studentOneName . ' made the Honor Roll.';
Martin Balon
43,651 PointsHi Sasa, problem is, that you have two students and therefore you need to print two sentences based on GPA of each student. Your code would only print one sentence - the conditional block would stop after else if - because the condition is true. Also, check the way you are echoing out sentences - if you put quotes around variable then you are not echoing out value stored in variable - you will actually echo just the name of the variable.
Here's the code that passes the challenge:
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;
}
Sasa Sanjic
963 PointsThank you Bapi and Martin for your effort to help me. :-)