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

Challenge error !

i run the code and its working but when check it , it give me error ! idont no why?

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

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

3 Answers

Hi raghdahesham2,

After your first if/else you repeated the variables for student two and this seems to be throwing off the tester. Take those out because all the variables are already defined at the top of the starter code.

The other thing is that this challenge requires a stricter formatting of the code.

Try it like this: (It's still your same code but the curly braces are formatted differently)

if ($studentOneGPA == 4.0) {
    echo "$studentOneName made the Honor Roll";
} else {
    echo "$studentOneName has a GPA of $studentOneGPA";
}

Do that for both of them and you should pass.

All of your logic was correct.

thank you Jason Anello alot ..its working now ^_^

Corey Johnson
PLUS
Corey Johnson
Courses Plus Student 10,192 Points

You need to concatenate the strings with the variable. In your code, you are including the variable inside quotes, which then treats it as a string literal. Instead, your echo statements should look something like this:

echo $variableName1 . ' has a GPA of ' . $variableName2;

Hope this helps.

Variables are evaluated within double quotes in PHP. Within single quotes they are not and would be treated literally.

thank you for reply and for this helpful note. ...but the error says "you need to check if studentOneGPA=4.0" and actually i did !!

Diar Selimi
Diar Selimi
1,341 Points

$studentOneGPA = 3.8;