Control Flow: Switch


#1

https://www.codecademy.com/courses/web-beginner-en-jZv2E/0/1?curriculum_id=5124ef4c78d510dd89003eb8#

Parse error: syntax error, unexpected T_ELSEIF on line 14


<!DOCTYPE html>
<html>
    <head>
		<title></title>
	</head>
	<body>
    <?php
    $name = "Danny";
    
    if ($name = Danny); 
    {
        echo "That is my name!";
    }
    elseif ($name = Josh); 
    {
        echo "Nope";
    }
    else 
    {
        echo "Not my name";
    }
    
    ?>
    </body>
</html>

I passed the lesson but the screen doesn't print anything, what is wrong with my code? Thanks!


#2

Niether of these should end in a semi-colon.


#3

Now it gives me error code:

Use of undefined constant Danny - assumed 'Danny' (line 10)That is my name!


#4







<?php
$name = "Josh";

if ($name = "Danny")
{
    echo "That is my name!";
}
elseif ($name = "Josh")
{
    echo "Nope";
}
else 
{
    echo "Not my name";
}

?>
</body>

I did this and it keeps producing: "That is my name!" regardless if i use $name = "Danny"; or $name = "Josh";


#5

Remember to use the comparison operator: ==. And yes, strings are always quoted else they look like undefined variables. That would have been the next fix.


#6

Thanks, much appreciated!


#7

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