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

Control Flow: Switch Forum

View Course » View Exercise

454 points
Picture
Submitted by
Michael Higgon
almost 4 years ago

I keep getting asked to "have 3 case blocks". What am I doing wrong?

 $i = 1;

 switch ($i) {
     case 0;
     case 1;
     case 2;
        print "I like Lucy";
    break;

    case 3;
    case 4;
    case 5;
        print "I love Lucy!";
    break;

    case 6;
    case 7;
    case 8;
        print "Lucy is amazing";

    break;

    default:

    print "I love Luck";

 }
?>
</body>

12 votes

permalink

Go back to exercise 5, click "Reset Code" and take a closer look at the character that must end each line that starts with the case keyword. Is it a semicolon? (Hint: it’s not.)

3117 points
Picture
Submitted by
Alex J
almost 4 years ago

1 Comment

Picture Michael Higgon almost 4 years ago

Thanks Alex!


0 votes

permalink

Had the same issue! Thanks for the hint, I had a semicolon after every case! :D

375 points
52273c2580ff3364c9001a29_31430765
Submitted by
Christopher Barkey
almost 4 years ago


0 votes

permalink

:

not;

969 points
5423572980ff337ea80006a1_104717000
Submitted by
Tom_Pi (minecraft username)
over 3 years ago


0 votes

permalink

i took tpatterson's idea and it still didn't work you have to change the switch statement part by turning it from

switch($i)

to
switch(2)
or something of the sort.

790 points
242122abeb4fd1987f4cf06435159a27?s=140&d=retro
Submitted by
Jayme
over 3 years ago

3 Comments

54195e92631fe9871c001c7a_67579294 Alexander over 2 years ago

LOL

54195e92631fe9871c001c7a_67579294 Alexander over 2 years ago

Ty typoy kak Labynov

54195e92631fe9871c001c7a_67579294 Alexander over 2 years ago

Labynov LOL