Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Basics Daily Exercise Program Conditionals

Error 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?

$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";

Your last echo looks off I think it should be $studentTwoGPA and not $studentOneGPA

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles:

Yasss that worked! Thank you that was really useful :)