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 trial

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,885 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.