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 trialnicolabell
18,212 PointsError is ' Bummer! You will need to create separate if statements for each student' but I have - output is working fine
The output looks fine for this although the line breaks are not working- is this what's stopping this from passing?
<?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" . "\n";
} elseif ($studentOneGPA != 4.0) {
echo $studentOneName . " has GPA of " . $studentOneGPA . "\n";
}
if ($studentTwoGPA == 4.0) {
echo $studentTwoName . " made the Honor Roll" . "\n";
} elseif ($studentTwoGPA != 4.0) {
echo $studentTwoName . " has GPA of " . $studentOneGPA . "\n";
}
?>
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! The Bummer! message may be a bit misleading here, but the idea is that the grade is either 4.0 (perfect) or it isn't. There is no other option, so it's wanting these in an "if/else" statement, but you're using elseif
. Once you change your elseif
to an else
statement, you will start receiving another "Bummer!" about not getting the right output. Currently you are printing " has GPA of", but the instructions say to print "has a GPA of". Note the omission of the indefinite article "a" in your version.
Although, this doesn't affect the challenge, the echo in the elseif
statement is a bit incorrect. Had that executed you would echo out the name of student two and the grade of student one. Also, for some reason, you are doing a lot of unnecessary concatenation, which works just fine, but in my opinion makes your code a bit less readable and more complicated to follow. I'll show you how I did the first one:
if ($studentOneGPA == 4.0) {
echo "$studentOneName made the Honor Roll\n";
} else{
echo "$studentOneName has a GPA of $studentOneGPA\n"; // note the addition of the word "a" here
}
Hope this helps!
nicolabell
18,212 PointsYasss that worked! Thank you that was really useful :)
jessecarter
8,444 Pointsjessecarter
8,444 PointsYour last echo looks off I think it should be $studentTwoGPA and not $studentOneGPA