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

Problem with the Conditionals challenge

it keeps telling me to add else blocks. Can't seem to see what I'm doing wrong

index.php
<?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){
  "$studentTwoName has made the Honor Roll";
}
elseif($studentOneGPA != 4.0) {
 "$studentOneName has a GPA of $studentTwoGPA"; 
} 
else{
  "$studentTwoName has a GPA of $studentOneGPA";
}
?>

2 Answers

Antonio De Rose
Antonio De Rose
20,880 Points

you have got 2 students

one - 4.0 two - 3.8

condition - check ALL students, whom have made honor, if it is 4.0, or else need not have to specifically 3.8, it could be anything where the code at present does not know what is the other s value

when you start an if with studentOne, the else if, should also should check studentOne.

best case would be to have 2 separate if's within each if, checking one student per if, and else, I think you should not use else if

I have figured it out and solved the challenge. Each student was to be treated as a seperate case scenario and as such would have seperate if and else blocks.