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

Control Flow: Switch Forum

View Course » View Exercise

1354 points
84ca8cd0e22db649ff33237c815cff2c?s=140&d=retro
Submitted by
boardPlayer67111
over 2 years ago

Suggestion regarding 6/6

I've solved my query now, but I was at a loss as to why the following code wouldn't let me proceed.

$i=1;
switch($i):
    case 0:
    case 1:
    case 2:
        echo "$i is one of 0,1, or 2";
        break;
    default:
        echo "$i is not one of 0,1, or 2";
endswitch;

I didn't realise that the dropping through 3 cases did not count as "3 cases" for the purposes of the exercise. Maybe this could be added explicilty to the exercise instructions, or even the hint.


0 votes

permalink

I just got this question too...
So I solve it like below:
$i=3
switch($i):
case 1:
case 2:
case 3:
echo "i is between 1 and 3";
break;break;break;
default:break;
endswitch;

Hah....

413 points
3c78625817f6afd38cf2ddb98ce2cd91?s=140&d=retro
Submitted by
A_Zhan
over 2 years ago