Am I getting it? - All on your own


#1

I wrote te following code:

<?php
    $age = 6;
    switch ($age) {
        case 1: ($age <= 6)
            echo "you should go to play!";
            break;
        case 2: ($age > 6)
            echo "you should study!";
            break;
        case 3: ($age <= 18)
            echo:"you should study!";
            break;
        case 4: ($age > 18)
            echo: "you should work!";
            break;
    }
?>
</body>

The result of it: Parse error: syntax error, unexpected T_ECHO on line 11

However, I got a congratulation message, saying I'm good to go.

What's wrong? Can anybody help me, please.


#2

Not sure on PHP syntax, but your echo's are inconsistent.

echo
echo:

I'm pretty sure they should be the first one.


#3

You're getting the syntax for a switch statement wrong:

switch ($var) {
    case (expr1):
         // do something
         break;
    case (expr2):
        // do something else
        break;
    ....
    
}

This does the first thing if expr1 is equal to $var. There's no way to check if it is smaller than or some other inequality. To do that, you would have to check all the possibilities that it could be equal to.

Also as @cadecodes commented: the correct syntax for echo is:

echo "Your text here";