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 Arrays and Control Structures PHP Conditionals School's Out

Erik Robles
PLUS
Erik Robles
Courses Plus Student 10,635 Points

Code not working for .69 and below GPA. ???

Hello. My code seems to work except when I input .69 or lower into the GPA. Here is the snapshot: https://w.trhou.se/cwd Thank you.

$firstName = 'Alena';
$lastName = 'Holligan';
$currentGrade = 9;
$finalAverage = .60;
$messageBody = '';

if (!$firstName || !$lastName) {
   echo 'Please enter a student name';
}elseif ($currentGrade < 9 || $currentGrade > 12) {
   echo 'This is only for high school students. Please enter a grade between 9 and 12.';
} else {
    if ($finalAverage < .70) {
      $mesageBody = 'We look forward to seeing you at summer school, beginning July 1st!';
    }else {
       switch ($currentGrade) {
          case 9:
            $messageBody = 'Congratulations on completing your freshman year in High School! We’ll see you on September 1st for the start of your sophomore year!';
         break;
         case 10:
            $messageBody = 'Congratulations on completing your sophomore year in High School! We’ll see you on September 1st for the start of your junior year!';
         break;
         case 11:
            $messageBody = 'Congratulations on completing your junior year in High School! We’ll see you on September 1st for the start of your senior year!';
         break;
         case 12:
            $messageBody = 'Congratulations! You’ve graduated High School! Don’t forget to come back and visit.';
         break;
         default:
            $messageBody = 'Error: Grade level is not 9-12!';
            break;
       }
    }
    echo "Dear $firstName $lastName\n";
    echo $messageBody;
}

$mesageBody = 'We look forward to seeing you at summer school, beginning July 1st!'; echo $messageBody; These are two different variables because they are spelled differently.

Erik Robles
Erik Robles
Courses Plus Student 10,635 Points

Thank you Kyle McCullen. It was so small I didn't catch it. Thank you for the double set of eyes. I really appreciate it. I think I need to start using my glasses. Cheers.

1 Answer

jamesjones21
jamesjones21
9,260 Points

good pair of eyes, hard to debug the code in the workspace editor, when debugging code, always check the variable names and also check the closing brackets of where the end of each statement, happy coding :)