This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Habib Rehman
over 8 years

Oops, try again. Make sure you have three case blocks!

I have written a switch case program against statment:

Create a switch statement with 3 different cases and a default case if you wish. Feel free to use the alternative syntax as well!

but it gives errror: Oopps, try again. Make sure you have three case blocks. I’m clearly making three cases

    <!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <?php
            $our_var = 33;
            switch($our_var)
            {
        case $our_var < 1:
             echo "Maybe i know but not in a mood to know";
             break;
        
        case $our_var == 33:
            echo $our_var;
            break;
        
        case $our_var > 201;
            echo "Just a random case wich wont work";
            break;
        
        default:
            echo "This wont work either";
            break;
     }
    ?>
    </body>
</html>

Answer 55f656d551b8876d160000c8

4 votes
Best answer

Permalink

This community is so in active. What do you do if anyone gets stuck anywhere doing code academy i figured it out myself. The cases worked if we juts put the string in the case e.g

$our_var = "something";
switch ($our_var)

case "anything"
echo "This isn't right";
break;

case "something"
echo "right one";
break;

default:
echo "anything for everything";
break;
points
Submitted by Habib Rehman
over 8 years

Answer 5612d5c73e0ec893610002b2

0 votes

Permalink

your issue is that you have a semicolon after the third case rather than a colon. fix it and watch in amazement as your code works

points
Submitted by Bret Wagner
over 8 years

Answer 55f64b7451b887f4d1000831

-2 votes

Permalink

Create a switch statement with 3 different cases and a default case if you wish. Feel free to use the alternative syntax as well!

points
Submitted by Abu Ishak
over 8 years

1 comments

Habib Rehman over 8 years

what’s that?