Output error? Or am I missing a step?



It outputs "The light is burnt out." Shouldn't it be "Turn the light on!"?

        // Write your if/elseif/else statement here!
        $lightswitch = "off";
        if($lightswitch = "on") {
            echo "The light is burnt out.";
        else {
            echo "Turn the light on!";


You've used an assignment operator in your if statement's comparison instead of a comparison operator.

Read more: http://php.net/manual/en/language.operators.php


I see... so I should use == in place of the = after the if statement (not the defining of lightswitch). Which raises the questions of what was the code doing with the assignment operator? I read that link, but I still am uncertain about how it works behind the code in this circumstance.


That returns the value that was assigned so what we have is:

if("on") ...

An empty string "" or the string "0" are considered FALSE, everything other string is considered TRUE.

So that if statement will always be TRUE.

You can read more about what is considered FALSE over here http://php.net/manual/en/language.types.boolean.php


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.