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 PHP Basics Daily Exercise Program True PHP

Miguel Nunez
Miguel Nunez
3,266 Points

Code challenge advice!!

Create a new variable name $booleanTwo. Set $booleanTwo equal to the result of comparing the variable $a as IDENTICAL to the string "5".

$a = 5; //Place your code below this comment $booleanOne = true;

index.php
<?php
$a = 5;
//Place your code below this comment

?>

4 Answers

Daniel Gauthier
Daniel Gauthier
15,000 Points

Hey Miguel,

The second part of the challenge is basically asking you to set a variable, although the challenge does tend to create some confusion about what it's actually asking for.

The working code is:

<?php
$a = 5;
//Place your code below this comment

$booleanOne = true;

$booleanTwo = $a === "5";

?>

Notice that the variable $booleanTwo is created, then it is assigned a value of $a identical (three equals signs) to the string "5".

Good luck with the course!

Miguel Nunez
Miguel Nunez
3,266 Points

I almost understood everything until you add double quotes to the 5 why is that?

Daniel Gauthier
Daniel Gauthier
15,000 Points

Hey again Miguel,

I just want to clarify that the code I supplied is what the challenge wanted you to type in :D

The challenge asked that we assign the variable $booleanTwo a statement reading:

$a === "5"

Which is really just a really convoluted way of showing how to compare a variable's type and value to another variable/value, while also serving the purpose of returning 'false' as the result of the assignment.

Since the double quotes surround the 5 in the assignment, the five becomes a string containing the character 5.

The identical operator ( === ) checks to see if the values/variables on both sides of the operator have the same value -and- the same type (string, integer, boolean etc).

Since a string character 5 is not identical to the integer 5 assigned to the $a variable at the top of the code challenge, the $a === "5" assignment will evaluate to false.

So basically, the variable $booleanTwo is asking the parser "Is this 5 (integer) the exact same as this 5 (string)?" and the parser is inspecting them and revealing that they are not identical because they have different types.

Since the two values are not identical, the final result of the assignment statement will be:

$booleanTwo = false;

Hope this helps clear that up a little :D

lifelonglearner
lifelonglearner
7,280 Points

The second question in the challenge is worded very poorly and should be revised.

Miguel Nunez
Miguel Nunez
3,266 Points

Wow those code challenges will try to trick you by forcing you to really think lol I didn't realize my mistake until I realized What they wanted exactly until you explained it to me ok it makes since then thanks Daniel.

Greg Sargent
Greg Sargent
3,942 Points

Thanks for the explanation Daniel. I would have never figured that out.