PHP PHP Basics Daily Exercise Program True PHP

Create a new variable name $isIdentical. Compare the variable $a as identical (equal AND of the same type) as the string

I keep getting the error message Oops! It looks like Task1 is no longer passing.

I've tried several different methods. My current code is:

index.php
<?php
$isIdentical = "true";
$a = 5;
$booleanOne= $a ==="5";
?>

What am I doing wrong... Please help!

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 144,854 Points

Hi Leanne,

You are more or less on the right track, but there seems to be a few things going wrong here. First, a good note to remember is that instructions for challenges need to be followed exactly as they are written.

With that in mind, the first thing is I no longer see the comment that was there that instructed you to:

//Place your code below this comment

You have some code that is out-of-place and may crash the challenge.

Second, you have created a variable $booleanOne that was not asked for, so this will need to be deleted.

Third, the instructions asked for the boolean true to be assigned to $isBoolean, but you have assigned the String "true", and also to the wrong variable.
Note: once you add quotation marks, everything inside the quotes becomes a string.

Finally, the result of the comparison needs to be stored in the variable $isIdentical.

I don't normally post the correct solution, but I feel with the above explanations, seeing the corrected code will be of the most learning benefit.

<?php
$a = 5;
//Place your code below this comment
$isBoolean = true;
$isIdentical = $a === "5";
?>

I hope this helps. Keep Coding! :) :dizzy:

Hi Jason, Thank you... I learn best from seeing the correct code. After trying several ways of working it out myself and watching the video back a few times I decided to look at other solutions on the forum. I think the code that I ended up with was an incorrect solution from another forum. This looks a lot more like what I'd originally written. I think where I was going wrong was the == as it needs to be a ===. I'm sure I'll get my head fully around this eventually. Probably when I've forgotten to debug as I'm going along and broken something that will take me hours to fix ;-) Again... Thanks for your help. Much appreciated! Regards Leanne

Thanks for the help was having problems in comparing the the String variable because I was creating a variable that was not being asked for.