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 trialLogan Fox
Courses Plus Student 3,379 PointsPhp method not working
Im not quite sure what I'm doing wrong. can someone help me?
<?php
include("class.palprimechecker.php");
$checker = new PalprimeChecker();
$checker->number = 17;
$checker->isPalprime();
echo "The number " . $checker->number;
if isPalprime($checker->number){
echo "is" . ;
else{
echo "is not" . ;
}
echo " a palprime.";
?>
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! I received your request for assistance. There are a few things going on here. First, you're trying to see if isPalprime
is true or not. But the way you're going about it is indicating to PHP that you're looking for a variable named isPalPrime instead of the result of calling that object's method by the same name. On a side note, you made a small error in capitalization here which will also affect the code. You're trying to pass in the number that we set up originally. But the method we're looking at doesn't have any parameters and accepts no arguments. It's the reason we set up the number in the previous steps.
Here was my solution, and I'll try to walk you through it:
<?php
include("class.palprimechecker.php");
$checker = new PalprimeChecker(); // create a new PalprimeChecker object
$checker->number = 17; //set that objects "number" property to 17
echo "The number $checker->number ";
if ($checker->isPalPrime()) {. // call the isPalPrime method on the $checker and see if the answer returned was true
echo "is"; //print this if the result returned was true
} else { //otherwise
echo "is not"; // print this if the result was false
}
echo " a palprime."; //print this no matter what
?>
Hope this helps!
Logan Fox
Courses Plus Student 3,379 PointsNevermind, I got it! It was the period on the same line as "if"
Logan Fox
Courses Plus Student 3,379 PointsLogan Fox
Courses Plus Student 3,379 Pointsso I did this but now it says task one is not passing