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

Control Flow: Switch Forum

View Course » View Exercise

396 points
Picture
Submitted by
Tyler Seabury
about 3 years ago

I wrote a case, yet it does not seem to care?

What is wrong with this?

<?php
    $fruit = "Apple";

    switch ($fruit) {
        case 'Apple':
            echo "Yummy.";
            break;
        case 'Pear':
            echo "OH, a pear.";
            break;
        default:
            echo "That's not a fruit bro.";
    }

    ?>

Clicking 'submit' results in this:

Oops, try again. Make sure you make at
least one case block!


4 votes

permalink

The space between the "}" and the "?>" seems to generate the error.
After trying a lot of different things i removed the extra line between them and it passed my code. ;)

787 points
E3b802cf4b89aa35575805347448a9ea?s=140&d=retro
Submitted by
Eduardo Isla Venegas
about 3 years ago

1 Comment

5103d24bb7cd04aaea003f1d_335520655 Daniel Clayton over 2 years ago

I had the same problem and this was the only fix that worked.


1 vote

permalink

Both your code worked for me. Try pressing Reset Code, Ctrl + F5, or F5 and complete the exercise again.

2570 points
56ec11ba1ec4b00bc400069e_656519138
Submitted by
Gaurang Tandon
about 3 years ago


0 votes

permalink

Seems to be a bug with how answers are evaluated. I deleted the entire PHP code element and re-typed it with this:

<?php 
$fruit = 'apple';

switch ($fruit) {
    case 'apple':
        echo "OH! An apple!";
        break;
    case 'pear':
        echo "OH! Pear me!";
        break;
    case 'clemintine':
        echo ":o";
        break;
    default:
        echo "BRING ME FRUIT DAMNIT!";
}
?>

Successfully submitted the first time.

396 points
Picture
Submitted by
Tyler Seabury
about 3 years ago

1 Comment

56ec11ba1ec4b00bc400069e_656519138 Gaurang Tandon about 3 years ago

Well, the aim of the exercise is to learn about switch statements; so it isn't a wonder you can pass with modified strings.