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 Simple PHP Application Wrapping Up The Project Objects

Sajid Latif
seal-mask
.a{fill-rule:evenodd;}techdegree
Sajid Latif
Full Stack JavaScript Techdegree Student 22,368 Points

Help needed

Im not strong at the object orientet questions.. please help :smile

palprimes.php
<?php

require_once("class.palprimechecker.php");
$checker = new PalprimeChecker();
$checker->number = 16661;





echo "The number ". $checker->number;
if ($checker->isPalprime(number)) {

   echo "is a palprime.";
  exit;

}else
  echo "is not a palprime.";

?>

5 Answers

Sajid Latif
seal-mask
.a{fill-rule:evenodd;}techdegree
Sajid Latif
Full Stack JavaScript Techdegree Student 22,368 Points

Ive tried with this, but not working... hmm.. strange

<?php

require_once("class.palprimechecker.php");
$checker = new PalprimeChecker();
$checker->number = 16661;



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

if ($checker->isPalprime()) {
   echo "is a palprime.";
  exit;
}

} else {
  echo "is not a palprime.";
}

?>

I've gone through the task.

Stage 5/7 :

PalprimeChecker objects have a method called isPalprime(). This method does not receive any arguments.

So you don't need to send anything into the method.

This is the completed code:

<?php

include 'class.palprimechecker.php';
$checker = new PalprimeChecker;
$checker->number = 16661;

echo "The number {$checker->number} ";
if ($checker->isPalprime()) {
  echo "is";  
} else {
  echo "is not";
}
echo " a palprime.";

?>

I imagine your random 'exit;' was throwing it off! Your code would've acheived the correct outcome, but the challenge didn't like it.

It looks like you're missing some brackets for starters:

if ($checker->isPalprime(number)) {
   echo "is a palprime.";
   exit;
} else {
   echo "is not a palprime.";
}

Make sure you add the curly braces around the else block :-)

What's the question?

Sajid Latif
seal-mask
.a{fill-rule:evenodd;}techdegree
Sajid Latif
Full Stack JavaScript Techdegree Student 22,368 Points

Thanks for your help :)

Now I added the curly braces. But the number 16661 is giving me a headeach. It was before 17 but I have to change it to 16661.

What do you think: is 16661 a palprime? Assign the number property of $checker a value of 16661. Be sure to refresh the preview before you finish this step to find out.

Have you refreshed the preview screen? Also, is it giving you an error message back?

Sajid Latif
seal-mask
.a{fill-rule:evenodd;}techdegree
Sajid Latif
Full Stack JavaScript Techdegree Student 22,368 Points

Yes. It is giving me this BUMMER:

Bummer! Please change the number property. We checked the number 17 last task; we're moving on to numbers with at least three digits. :)

Ah, I imagine this is giving you a syntax error:

<?php

if ($checker->isPalprime(number)) {

because number is not a valid variable. In fact, does 'isPalprime' need an argument?

You're storing the value inside the checker with

<?php

$checker->number = 16661;
<?php

if ($checker->isPalprime(number)) {

should be

<?php

if ($checker->isPalprime($checker->number)) {

BUT, your $checker already has the $checker->number 'saved' inside of it.

You shouldn't have to do this:

<?php

if ($checker->isPalprime($checker->number)) {

at all.

Try not sending in an argument (remove number):

<?php

if ($checker->isPalprime()) {

or updating as above.