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

conditionals

i am having a hard time getting the last line of the variable

index.php
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;

$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;

//Place your code below this comment
var_dump($studentOneGPA ==4.0);
var_dump($studentTwoGPA ==4.0);
if ($studentTwoName == 4.0) {
echo 'made honor roll';
} else ($studentOneGPA = 3.8) {
  echo 'has a GPA of ""';
}

?>

2 Answers

John Lack-Wilson
John Lack-Wilson
8,181 Points

The challenge is asking you to check if each student has a GPA of 4.0, there is no need to have any var_dumps, so you will need exactly 2 if statements and 2 else statements to see if studentOneGPA is 4.0 and if studentTwoGPA is 4.0.

If either of these conditions is true it asks you to echo "NAME made the Honor Roll" - remember we can use double quotes and the variable name to expand the variable into the value it has been assigned. For example if $name = "Chiratidzo", then we can use:

echo "Hello, $name"

The above code will replace $name with the value of Chiratidzo. Giving us "Hello, Chiratidzo".

It is also asking that when those statements are NOT true (i.e. using else statements after each if statement), then we must echo "NAME has a GPA of STUDENT GPA" - just as before we can use double quotes to expand the NAME and the STUDENT GPA variables.

What am I doing wrong here?

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

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

?>

I have also tried using the == comparison operator and it isn't working :/

John Lack-Wilson
John Lack-Wilson
8,181 Points

Good job on the logic - it's all correct. The problem is that the challenge asks you to echo "NAME has a GPA of STUDENT GPA", whereas yours says "NAME has a STUDENT GPA".

You need to change your echo statements to match exactly what the challenge expects it to say.

It should be similar to this (not exactly):

echo "$studentName has a GPA of $studentGPA";