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

Maarten Davidse
Maarten Davidse
2,329 Points

Code Challenge, PHP Basics course, 'else' and 'if' statements

Hi Guys,

I am doing the PHP Basics course, and ran in to some trouble while doing the code challenge on 'if' and 'else' statements. I don't understand what I am doing wrong, especially since the code produces the right results in preview mode. I hope some of you can find out what kind of mistake I am making.

thanks in advance!

The assignment is: Check if each student has a GPA of 4.0. If the student has a GPA of 4.0, use the students name variable to display "NAME made the Honor Role". If not, use the variable to display "NAME has a GPA of GPA".

The code I wrote is:

<?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 Role";
} else {
  echo "$studentOneName has a GPA of GPA"; 
}

if ($studentTwoGPA == 4.0) {
  echo "$studentTwoName made the HonorRole";
} else {
  echo "$studentTwoName has a GPA of GPA";
}

?>

1 Answer

Robbert Slijkhuis
Robbert Slijkhuis
3,007 Points

I'm with Edward, the assignment does ask you to use the name and gpa variables.

echo "$studentTwoName has a GPA of GPA";

Probaly should be:

echo "$studentTwoName has a GPA of $studentTwoGPA";
Edward Stedman
Edward Stedman
10,368 Points

Whoops; probably should have made sure I put the code correctly in my reply. Thanks for the correction!

Maarten Davidse
Maarten Davidse
2,329 Points

Thanks! that was indeed the problem :) Still got error, after adding the variable, but that was because of spacing. I passed the test! hehe.