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 trialMaxwell Kendall
Front End Web Development Techdegree Student 12,102 PointsConditonals Challenge task 2 of 3
I cant figure out how to test to see if the variable name is equal to the string mike
This is what I have tried to do:
<?php
$name = "Mike" if($name = "Mike"){}
?>
I know this is pretty stupid I just cant figure it out, thanks!
<?php
$name = "Mike"
if( $name = "Mike"; ){
}
;
?>
2 Answers
Julian Aramburu
11,368 PointsHi mate! You almost got it right! When you are trying to compare something to something you should use == double equal signs for "equal" and === triple equal signs for "strict equal" otherwise if you use just one set of equal sign you are "re-declaring" the variable... so the if statement should be:
<?php
if($name === "Mike") {
//something happens in here if the condition is met
}
Also you have an extra semi colon after "Mike" so fix that too :)!
Hopes you find this useful!
Cheers and keep coding!
Ted Sumner
Courses Plus Student 17,967 PointsYou also need a semicolon after your variable assignment:
<?php
$name = "Mike";
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 PointsEdited by adding
<?php
for formatting.