Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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