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

Control Flow: Switch Forum

View Course » View Exercise

118 points
166411c53c69d2b6973da4c7bd4125eb?s=140&d=retro
Submitted by
Udit Bhansali
over 4 years ago

What can't I complete the exercise if my code is right?

What is wrong with my code?
My code gets executed by the editor but I get this error whenever I submit the code.

Oops, try again! Make sure you have at least three breaks!

  <!DOCTYPE html>
    <html>
        <head>
            <title></title>
        </head>
<body>
        <?php
         $smart= 4;

     switch ($smart) {
        case 1:
        case 2:
        case 3:
            echo "She's smart!";
            break;
        case 4:
        case 5:
            echo "I doubt she's smart";
            break;
        default:
            echo "She isn't smart";
     }
    ?>
    </body>
</html>

3 votes

permalink

include "break;" in the default case

default:
  echo "She isn't smart";
  break; 

692 points
50c8aa845f1c4c93f200652a_924031435
Submitted by
excowboy
over 4 years ago

2 Comments

166411c53c69d2b6973da4c7bd4125eb?s=140&d=retro Udit Bhansali over 4 years ago

Thanks! I didn't notice that

96106f0028319434d60ef1e6c41d7e64?s=140&d=retro jasen about 4 years ago

agreed, thanks...very sneaky that missing 'break;'


0 votes

permalink

You need to complete at least 3 break.... complete case 4 .I think it will work .

262 points
D34c6390ed488492b1a30283636e22f4?s=140&d=retro
Submitted by
Khandaker Limon
over 4 years ago


0 votes

permalink

I have a similar doubt .
Please help.
<!DOCTYPE html>





<?php
$wow=5;
switch($wow){
case 1:
echo "nope";
break;
case 2;
echo 'nopes again';
break;
case 3;
echo 'nopes yet again';
break;
default:
echo 'It is not 0 ,1 or 2

I dont know what number it is!!';
break;
}
?>

463 points
Picture
Submitted by
Suraj Kohli
over 4 years ago