Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Basics Daily Exercise Program Conditionals

Cliff Jackson
Cliff Jackson
2,886 Points

Bummer! syntax error, unexpected 'echo' (T_ECHO) in index.php on line 12 any ideas on what the error is here?

trying to get past this challenge but no success....not entirely sure if i have got the else bit correct as the way these are worded is terrible

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

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

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

?>

7 Answers

The problem that the challenge is having is with the "made the honor roll" statement.

You have written:

echo "$studentOneName made the honor role";

But the challenge wants:

echo "$studentOneName made the Honor Roll";

It is the same error for the second student as well, just change these strings and you should pass (the capital letters are important for these challenges)

An else statement is run if the if and else if statements above it have all failed and because of this you don't need to give them any conditions. This is why you are getting the syntax error, all you need to do is remove the condition from the else statement , like this:

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

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

Also when I ran your code it was getting an error saying the wrong output was received. Treehouse is really picky so you need to make sure it is outputting exactly what the challenge says with exact capitalisation and everything (I fixed this in the example above).

Cliff Jackson
Cliff Jackson
2,886 Points

this still does not work says bummer incorrect output

The code from my answer passes the challenge for me, are you sure that yours has exactly the same text inside the quotes in the echos (these challenges are really picky about that)

Cliff Jackson
Cliff Jackson
2,886 Points

code does work on a normal text editor with output to the browser???

Cliff Jackson
Cliff Jackson
2,886 Points

still not working spent over an hour checking spelling etc nothing works

Can I see a snippet of your new code that you are trying?

Cliff Jackson
Cliff Jackson
2,886 Points

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

Cliff Jackson
Cliff Jackson
2,886 Points

Thanks!.... could not spot the problem i spelt role (roll) wrong and the case sensitivity was incorrect. Some days you just can't get it...easier to walk away and go back a day later sometimes