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 trialLorenzo Leva
12,262 PointsTrue PhP chalange.
Hi, I dont know what I'm doing wrong in this chalange. Please help me. link: https://teamtreehouse.com/library/php-basics-2/daily-exercise-program/true-php
<?php
$a = 5;
//Place your code below this comment
$booleanOne = true;
$booleanTwo = $a === "5";
?>
1 Answer
Connor Walker
17,985 PointsThe problem with your code is that you havn't included the if statement like this:
<?php
$a = 5;
//Place your code below this comment
$isBoolean = true;
if($a === '5'){
$isIdentical = true;
} else {
$isIdentical = false;
}
?>
If you where trying to use the ternary if statement then they must look like this variable = condition ? if-true : if-false
Example (This code will pass the challenge) :
<?php
$a = 5;
//Place your code below this comment
$isBoolean = true;
$isIdentical = $a === '5' ? true : false;
?>
Tobias Karlsson
2,751 PointsTobias Karlsson
2,751 PointsThe problem with his code is actually improper naming of variables. The logic is perfectly fine and this works.
If you only want to return or get the value out of a boolean expression you should probably never use
if
-statements nor the shorthand ternary statement.Lorenzo Leva
12,262 PointsLorenzo Leva
12,262 PointsThank you really much.
Alex Forseth
8,017 PointsAlex Forseth
8,017 PointsWhen did we learn the "? true : false;" part? I get that its a boolean but wtheck does "? true : false" mean? I have not yet seen syntax that looks like that in this course.
Connor Walker
17,985 PointsConnor Walker
17,985 PointsI'm not sure if they do show this form of if statement on the PHP course but you can see it used here in the C# course (languages share a lot of the same principles). You can also see it here on the PHP docs