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 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

palprimes.php
<?php

include("class.palprimechecker.php");

$checker = new PalprimeChecker();

$checker->number = 17;

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

?>

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 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:

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."