January 2001
Beginner
312 pages
6h 4m
English
The switch statement enables you to execute one or more statements when a specified expression's value matches a label.
The script takes on the following layout:
switch (expression)
{
case label1:
statementlist
case label2:
statementlist
}
In the following example, the value inputted into the prompt box determines which statements are run (the before and after are shown in Figures 7.11 and 7.12):
<script language="JavaScript"> <!-- Cloaking device on! var yourchoice; yourchoice = prompt("Choose a number between 1 and 4", "1, 2, 3 or 4") switch (yourchoice) { case "1": alert("You typed in a 1"); break; case "2": alert("You typed in a 2"); break; case "3": alert("You typed in a 3"); break; case "4": alert("You typed in a ...Read now
Unlock full access