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

Control Flow: Switch Forum

View Course

630 points
55c44da4e39efe034d0001d1_304216882
Submitted by
Leah C Pornillos
about 2 years ago

Control Flow: Switch Stuck on lesson 5

<!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 ' is somewhere between 1 and 5.';
    break;


case 6:
case 7:
    echo '$i is either 6 or 7.';
    break;

default:
echo "I don't know how much \$i is.";

;
?>

Does anyone know how to do this correctly?


-1 votes

permalink

Hi Leah!

I believe your biggest problem is that you forgot your { }'s

It should look like this:

switch ($i){
case 0:
echo '$i is 0.';
break;

case 1:
case 2:
case 3:
case 4:
case 5:
echo ' is somewhere between 1 and 5.';
break;
case 6:
case 7:
echo '$i is either 6 or 7.';
break;
default:
echo "I don't know how much $i is.";
}

HOWEVER, you can also use
switch ($i):

endswitch;

364 points
Picture
Submitted by
Salena Mahina
about 2 years ago