PHP Build a Basic PHP Website (2018) Adding a Basic Form Objects

Paul M
Paul M
16,370 Points

I am stuck on question 4 with PHP

I am stuck on question 4



$checker = new PalprimeChecker();

$checker->number = 17;

echo "The number" . $checker->number . " ";
echo $checker;
echo " a palprime.";


2 Answers

Jason Anders
Jason Anders
Treehouse Moderator 145,036 Points

Hey Paul,

You are doing great, but I feel you missed a vital part of Task 4's instructions. It wants you to enclose (and still use the second preloaded echo statement) inside of a conditional that will check to see if the number passed in is or is not a palprime. So, you do need to modify the preloaded code a bit, but it all still needs to be there or the code checker gets cranky. :)

Here you would use an if statement to check the number using the isPalprime() method that comes with the Class. This will return a Boolean. So, if true, you echo "is", and if false, you echo "is not".

Here's the corrected code (for task 4 and replaces only the second echo statement) for your reference. I hope it all makes sense. :)

if ($checker->isPalprime()) {
  echo "is";
} else {
  echo "is not";

Keep Coding! :dizzy:

Veronica Rivera
Veronica Rivera
32,564 Points

Jason Anders Answer is good but you also need to add the parameter for the isPalprime method. This is how I wrote mine.

if (!$checker->isPalprime($checker->number)) {
    echo "is not";
} else { echo "is"; }

Here I am checking to see if the value is NOT palprime. If that method returns false, it will return the first echo statement "is not."