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

General Discussion

Build a Simple PHP Application > Wrapping Up The Project > Objects: Task 6/7

Question: 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.

My Answer: <?php include_once('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."; ?>

Any Suggestions?

3 Answers

$checker = **new** PalprimeChecker;

Correct me if I am wrong, but Isn't that JavaScript syntax for declaring a new variable?

You have some quote placement issues that are fowling up the results. When using double quotes take advantage of variable substitution and set the variables external to your echoes. Also explore using the ternary operator for single line conditional statements where you setting a binary value ( true vs false ) it is easy to read and will make your code cleaner.

<?php

include('class.palprimechecker.php');
$checker = new PalprimeChecker;

$checker->number = 16661;
$palprime_number = $checker->number;
// Check if number value is prime and set the is or is not value.
$palprime_status = ( $checker->isPalprime() ? "is" : "is not" );

echo "The number $palprime_number $palprime_status a palprime.";

?>

Thanks Mark. I like your approach.