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

Check if each student has a GPA of 4.0. If the student has a GPA of 4.0, use the students name variable .... Issue

Source: Question: 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".

Issue: per the instruction there to "check each student for GPA 4.0" if this, then that. But there are two students. So there are two if/else statements on each.

My solution didn't work, help:

if($studentOneGPA == 4.0){
echo "$studentOneName is made the Honor Role";
} else {
echo "$studentOneName is made the Honor Role";
}

if($studentTwoGPA == 4.0){
echo "$studentTwoName is made the Honor Role";
} else {
echo "$studentTwoName has a GPA of $studentTwoGPA";
}
index.php
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;

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

//Place your code below this comment

?>
John Lukacs
John Lukacs
26,806 Points

This challenge makes you wirte the else statements on there own lines to work

//Place your code below this comment
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; 
}
?>

2 Answers

Would love more of an explanation about what you mean by "else statements on their own lines" given that in the first code block it appears to me that they are. Also seems a nit picky thing to fail the challenge over when it produces the correct output regardless.

I got it thanks!

Steve Berrill
Steve Berrill
20,016 Points

yeh i also thought that was nit picking because in the video the demonstation was to use the $variable names in double quotation marks along with the text to output so i assumed it was ok to use this method instead of concatenating the variables with string.

Andrew Phythian : Andrew I completely agree with you about the challenge failing over how we come to the exact same output. I've noticed that happens quite frequently with the TH challenge checker. It'll want one specific result and if you don't give it, it'll "fail" you.

robert tanner
robert tanner
6,085 Points

Try spelling things inside a string correctly.