Prompt[]
Description[]
Checks a value for specific conditions and executes code when found.
Syntax[]
Switch(param1) {
case "sub_param1" :
<executable code>
break;
case "sub_param2" :
<executable code>
break;
case "sub_param3" :
<executable code>
break;
...
default:
<executable code>
}
Example[]
Switch(Dog) {
case "Bulldog" :
alert("GROWL");
break;
case "Chihuahua" :
alert("Bark!");
alert("Bark bark!");
break;
case "Basset Hound":
case "Beagle":
alert("Sniff sniff");
break;
default:
alert("Drool");
}
Notes[]
This is like a series and ifElse statements but cleaner to write. Adding two cases together without a break lumps them into an "or." In the example above, the third case is asking if the dog is a Basset Hound or a Beagle. Default cases do not need a break.