`

Multiple Selection using the Switch statement

It's possible to use a multiple selection statement called Switch as illustrated in t he following example:

	<!DOCTTYPE html> 
<!--Switch.html -->
<html>
<head>
<title> Switch Statement </title>
<script >
<!--
var choice;
var endorse_input = true; //it's true if input is endorsed
var list_type; //type of list initially as sa string
var start_tag; //beginning list item tag
var end_tag; //end list item tag
choice = window.prompt("Select a list style:\n" + " 1 (Lettered), 2 (Arabic numbered), 3 (Roman numbered)", "1");
switch (choice)
{
case "1":
start_tag = "<hol style = 'list-style-type: upper-alpha'>"
end_tag = "</ol>"
list_type = "<h2>Lettered List </h2>"
break;
case "2":
start_tag = "<ol>"
end_tag = "</ol>"
list_type = "<h2>Arabic Numbered List<h/h2>"
break;
case "3":
start_tag = "<ol style = 'list-style-type: upper-roman'>"
end_tag = "</ol>"
list_type = "<h2> Roman Numbered List </h2>"
break;
default:
endorse_input = false;
break;
} //end of switch
if (endorse_input === true)
{
document.writeln(list_type + start_tag);
for (var counter=1; counter <=3; ++counter)
document.writeln("<li>List item " + counter + "</li>");
document.writeln(end_tag);
} //end if
else
document.writeln("Invalid choice: " + choice);
// -->
</script>
</head>
<body></body>
</html>
If a user's variable could be equal to a known number of values and for each value, an appropriate action is taken.
See here the output of this program:


For more details, please contact me here.
Date of last modification: March 26, 2019.