This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Control Flow: Switch Forum

View Course

39 points
0434e0ed709715015faa52ea0a7471c2?s=140&d=retro
Submitted by
Habib Rehman
almost 2 years ago

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>

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;

39 points
0434e0ed709715015faa52ea0a7471c2?s=140&d=retro
Submitted by
Habib Rehman
almost 2 years ago


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

426 points
9a74e1277d8e32358137a88e715f067c?s=140&d=retro
Submitted by
Bret Wagner
almost 2 years ago


-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!

76 points
55f18a6895e378ef37000527_432257312
Submitted by
Abu Ishak
almost 2 years ago

1 Comment

0434e0ed709715015faa52ea0a7471c2?s=140&d=retro Habib Rehman almost 2 years ago

what's that?