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

Control Flow: Switch Forum

View Course » View Exercise

595 points
Bcb797686c3e76f47441b73d8351bba1?s=140&d=retro
Submitted by
Ish Kohli
almost 3 years ago

Why am I getting an error (Parse error: syntax error, unexpected T_SWITCH on line 10 ) ?

<!DOCTYPE html>





<?php
$fruit = orange

 switch ($fruit):
     case "apple":
         echo "Juicy";
         break;
     case "orange":
         echo "Sour";
         break;
     case "pomegranate":
         echo "Sweet";
         break;
 endswitch;
?>
</body>

1 vote

permalink

quotes around "orange" when declaring the variable?

209 points
54bd2804e39efe775100625b_135289754
Submitted by
Joe Bieniecki
almost 3 years ago


0 votes

permalink

Tested with both syntaxes ( { } and : endswitch)

Added the quotes on the variable declaration and added a default case at the botton.

switch ($fruit) {
case "apple":
echo "Juicy";
break;
case "orange":
echo "Sour";
break;
case "pomegranate":
echo "Sweet";
break;
default:
echo "You might have a vegetable there";
break;
}

209 points
54bd2804e39efe775100625b_135289754
Submitted by
Joe Bieniecki
almost 3 years ago

1 Comment

54bd2804e39efe775100625b_135289754 Joe Bieniecki almost 3 years ago

Guess cut and paste didnt preserve the indentations : ( sorry