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

Control Flow: Switch Forum

View Course » View Exercise

240 points
Picture
Submitted by
ComputerColumbus
about 2 years ago

Control Flow: Switch - Why doesn't code work?

This is my code:

$fruit = "Apple";

switch ($fruit) {
    case 1: 'Apple';
        echo "Yummy.";
        break;
    default:
        echo "It's not";
}

I don't understand the reason why the right (front end screen) gives me the default result. Shouldn't the front end agree with case 1? That fruit equals apple?


0 votes

permalink

I think the syntax is wrong, try " case 'Apple': " instead " case 1: 'Apple'; "

my code:
$fruit = "Apple";

switch ($fruit) {
    case 'Apple':
        echo "Yummy.";
        break;
    case 'Banana':
        echo "YAY";
        break;
    default:
        echo "It's not";
}

470 points
654c3ab4462a76e057de20547d93b466?s=140&d=retro
Submitted by
Aquemi
about 2 years ago