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

James Wells
James Wells
2,683 Points

Wrapping up the project Code challenge

Hello,

I am getting tripped up at Task 5/7, and if I do pass it...I will get an error at Task 6/7. My code looks like this:

<?php

require_once('class.palprimechecker.php'); $checker = new palprimechecker; $checker -> number = 17;

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

But I get the error that the output is not right. Is there something I missing here? I have been stuck on this for the past 2 hours...any help is appreciated!

James Wells
James Wells
2,683 Points

Sorry for the messy code...still learning how to format my text and code properly on the forums..

7 Answers

James Wells
James Wells
2,683 Points

Thanks Jason! That worked, and I have gone through the video and now understand why variables are capitalized. You've been a great help! P.S I passed the challenge!

Shaun Dixon
Shaun Dixon
10,944 Points

The main thing you are asking the php code here is to determine if the result of the function isPalprime TRUE or FALSE.

So the way you want to word your conditional is:

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

The php operator == means "equal to" or "equal". So what you are asking the code is, If isPalprime() equals TRUE, display is. If it does not equal TRUE (so FALSE) then echo "is not".

I hope this helps, I have only been doing PHP for about 1 week now and I finished this course yesterday but understanding comes with practice.

Thanks

Shaun

James Wells
James Wells
2,683 Points

Unfortunately that did not solve my issue...I still cannot pass Task 5 because it still says "Something in the output is not quite right." I am completely stuck on this...and I have been trying to understand it for the past 6 hours...

Hi James,

Your if block should only be echoing "is" and you have it echoing "is palprime"

The else block should only echo "is not"

echo " a palprime."; should be left untouched and come after your if/else blocks

James Wells
James Wells
2,683 Points
<?php

require_once('class.palprimechecker.php');
$checker = new palprimechecker();
$checker -> number = 17;



echo "The number " . $checker -> number . " ";
if($checker->ispalprime() == TRUE) {
    echo "is";
} else {
    echo "is not";
}

?>

This is what I have so far...I did do echo " a palprime."; after the if and else blocks but still I got the same error.

You have another error that I missed the first time.

Check your capitalization on isPalprime()

I think if you fix that and get that last echo statement back in there after the if/else it should be fine.

Also you can go back to using if ($checker->isPalprime()) {

isPalprime() will return true or false so there's no need to compare it to true.

It's not an error. Function names in php are case-insensitive but variables are case-sensitive.

Although it's probably good form to match the capitalization used by the function declaration.

James Wells
James Wells
2,683 Points

Sadly that did not correct it either. The capitalization has been corrected and the if statement set to what you have given me but the error is still the same. I checked ALL spaces and everything looks good...but it will not let me pass. I will have to start this challenge over again and watch through the entire objects section again as I still do not understand this code....thanks for the help.

Well, if you feel you don't understand the code then that's a good idea.

Here's the code that I passed with so you can compare:

<?php

require_once('class.palprimechecker.php');
$checker = new palprimechecker();
$checker->number = 17;
echo "The number " . $checker->number . " ";
if($checker->isPalprime()) {
    echo "is";
} else {
    echo "is not";
}
echo " a palprime.";
?>