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 trialHans Blomberg
12,306 PointsChallenge is failing me but my code works just fine :-)
Just trying to be DRY here, come on!
<?php $studentOneName = 'Dave'; $studentOneGPA = 3.8;
$studentTwoName = 'Treasure'; $studentTwoGPA = 4.0;
//Place your code below this comment
echoGpa($studentOneName, $studentOneGPA); echoGpa($studentTwoName, $studentTwoGPA);
function echoGpa( $name, $gpa ) { if( $gpa == 4.0) { echo "$name made the Honor Roll\n"; } else { echo "$name has a GPA of $gpa\n"; } }
?>
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;
$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;
//Place your code below this comment
echoGpa($studentOneName, $studentOneGPA);
echoGpa($studentTwoName, $studentTwoGPA);
/*
if( $studentOneGPA == 4.0) {
echo "$studentOneName made the Honor Roll\n";
} else {
echo "$studentOneName has a GPA of $studentOneGPA\n";
}
if( $studentTwoGPA == 4.0) {
echo "$studentTwoName made the Honor Roll\n";
} else {
echo "$studentTwoName has a GPA of $studentOneGPA\n";
}
*/
function echoGpa( $name, $gpa ) {
if( $gpa == 4.0) {
echo "$name made the Honor Roll\n";
} else {
echo "$name has a GPA of $gpa\n";
}
}
?>
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Hans,
Martin is correct in the misnaming of the variable. But also, the challenge is not passing because the code you are submitting is not what the instructions ask for.
The instructions did not ask for a function. So, if you delete the function entirely, delete the two lines that are calling the function, and uncomment the other lines of code (with Martin's correction), the challenge will pass.
In Treehouse challenges, the instructions are specific and if not followed explicitly, you will receive the Bummer!
. So, just fix those up and you're good to go.
Keep Coding! :)
Martin Park
12,792 PointsMartin Park
12,792 PointsHi Hans I think the problem might be with the 2nd student:
echo "$studentTwoName has a GPA of $studentOneGPA\n";
Should be:
echo "$studentTwoName has a GPA of $studentTwoGPA\n";