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

Control Flow: Switch Forum

View Course » View Exercise

316 points
64e71c6c65550cf202c5257e1d56e8eb?s=140&d=retro
Submitted by
boytsb
about 4 years ago

Why don't have any action after pressed save & submit code?

04/06 Multiple Cases. Falling Through!

<!DOCTYPE html>





<?php
$i = 5;

switch ($i) {
    case 0:
        echo '$i is 0.';
        break;
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
        echo '$i is somewhere between 1 and 5.';
        break;
    case 6:
    case 7:
        echo '$1 is either 6 or 7.';
        break;
    default:
        echo "I don't know how much \$i is";
        break;
}
?>
</body>

0 votes

permalink

The code is fine, but the outputting is an Codecademy issues which they are looking to solve.

504 points
2b153953ef015ea1708bd5f306bd2bb6?s=140&d=retro
Submitted by
Roni
about 4 years ago

3 Comments

Picture Susie Gardner-Brown over 3 years ago

10 months later and it's still happening!! I have to submit again and again sometimes! Go back to previous lessons, and then come back, all in an effort to get it to accept what I've done and let me move on!!

Picture Alina K. about 3 years ago

You need to remove "somewhere" from "'echo '$i is somewhere between 1 and 5.';". This happened to me too, but after I removed "somewhere," the code actually worked.

6eb1c4a1d249f6db4972d503c109fded?s=140&d=retro BluePy about 3 years ago

^That did it. Thanks!


0 votes

permalink

switch ($i) {
case 0:
echo '$i is 0.';
break;
case 1:
case 2:
case 3:
case 4:
case 5:
echo '$i is somewhere between 1 and 5.';
break;

1228 points
52f07fbc548c358e90000e1a_385034243
Submitted by
carlosmante
almost 4 years ago


0 votes

permalink

Sometimes I give a space before ; and it works.

Here I put a space before : on the both cases we've to write:

    case 1:
    case 2:
    **case 3 :**
    **case 4 :**
    case 5:

549 points
5164480c2009ede2f800371c_741507914
Submitted by
Diana
over 3 years ago