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 trialNeslee Rodillo
19,615 Pointsi do not understand objects in php
Can someone explain this to me in laymans terms??
Challenge task 5 of 7 PalprimeChecker objects have a method called isPalprime(). This method does not receive any arguments. It returns true if the number property contains a palprime, and it returns false if the number property does not contain a palprime. (Tip: 17 is not a palprime.) Turn the second echo statement into a conditional that displays “is” or “is not” appropriately. The conditional should call the isPalprime method of the $checker object. If the isPalprime method returns true, then echo “is”; otherwise, echo “is not”.
My answer:
<?php
include "class.palprimechecker.php";
$checker = new PalprimeChecker();
$checker->number = 17;
echo "The number 17 ";
if (isPalprime($checker) !== FALSE) {
echo " is not";
}
echo " a palprime.";
?>
Ouctcome: Bummer, Try again
4 Answers
Chris Wiley
11,327 PointsTry this for a false check:
include("class.palprimechecker.php");
$checker = new PalprimeChecker;
$checker->number = 17;
echo "The number 17 ";
if (!$checker->isPalprime()) {
echo "is not";
}else{
echo "is";
}
echo " a palprime.";
?>```
Just put he ' ! ' in front if the object and invert the execution order.
Iaan Tatenda Ruwiza
12,712 Pointsinclude("class.palprimechecker.php"); $checker = new PalprimeChecker(); $checker->number = 17;
if($checker -> isPalprime()){ echo "The number " . $checker->number . " is a palprime."; } else { echo "The number " . $checker->number . " is not a palprime."; }
Jason Cullins
Courses Plus Student 4,893 PointsTo me, it looks like you have this backwards... but this:
if (isPalprime($checker) !== FALSE) {
should probably be:
if ($checker->isPalprime !== FALSE {
because you set:
$checker = new PalprimeChecker();
so now the methods are inside of your $checker object.
Hope this helps you.
John MacDonald
8,593 PointsHey Neslee
Instead of php if(isPalprime($checker) !== FALSE)
change it to php if(isPalprime($checker->name) !== FALSE)
I think that should work.
Hope this helps
John; \n\n