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

Control Flow: Switch Forum

View Course » View Exercise

114 points
C0e3f3eed7b2d931a539ec27db86d790?s=140&d=retro
Submitted by
Yusuf01
about 2 years ago

Is any other person stuck on 6/6? Because I am.

Hello everybody... I'm just stuck with 6/6, here is my code

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
    <?php
     $myNum = 2;
     switch ($myNum) {
    case 1;
         echo "Number is 1";
         break;
    case 2;
         echo "Number is 2";
         break;
    case 3;
         echo "Number is 3";
         break;
    default: 
             echo "Number is not there";
     }
    ?>
    </body>
</html>

and after clicking the save button, all I get is this

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

I believe I have my three case blocks complete, so I don't know what the problem is... can anybody help with get out of this, I'll be grateful...

Thanks


2 votes

permalink

Hi,

I think the problem here is that you have put semi-colons in place of colons on your "cases": try changing your code from this:

case x;
    echo "Number is x";
    break;

to

case x:
    echo "Number is x";
    break;

and change "x" to the number on each of them.

I hope this helps!
Tim

1115 points
9092398c5ae8ff80b6254d0d275ce55b?s=140&d=retro
Submitted by
Tim Fawkes
about 2 years ago

2 Comments

9271dcc1bd2057f1ccaefeb04735a6eb?s=140&d=retro EvenB about 2 years ago

Yep, this would be how you correct it. Yusuf01, you got it right at default: , I guess you just forgot that it's not semi-colons for case either

Fbaf234270436c72387d16c9d3aee862?s=140&d=retro Samantha Ma about 2 years ago

thanks!