Advertisement
RokiAdhytama

Switch Test - Chapter 9

Jul 3rd, 2022
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <html xmlns = "http://www.w3.org/1999/xhtml">
  3.    <head>
  4.       <title>Switching between XHTML List Formats</title>
  5.  
  6.       <script type = "text/javascript">
  7.          <!--
  8.          var choice,             // user’s choice
  9.              startTag,           // starting list item tag
  10.              endTag,             // ending list item tag
  11.              validInput = true,  // indicates if input is valid
  12.              listType;           // list type as a string
  13.  
  14.          choice = window.prompt( "Select a list style:\n" +
  15.              "1 (bullet), 2 (numbered), 3 (lettered)", "1" );
  16.              
  17.          switch ( choice ) {
  18.             case "1":  
  19.                startTag = "<ul>";
  20.                endTag = "</ul>";
  21.                listType = "<h1>Bullet List</h1>";
  22.                break;
  23.             case "2":
  24.                startTag = "<ol>";
  25.                endTag = "</ol>";
  26.                listType = "<h1>Ordered List: Numbered</h1>";
  27.                break;
  28.             case "3":
  29.                startTag = "<ol type = \"A\">";
  30.                endTag = "</ol>";
  31.                listType = "<h1>Ordered List: Lettered</h1>";
  32.                break;
  33.            default:
  34.                validInput = false;          
  35.          }
  36.      
  37.          if ( validInput == true ) {            
  38.             document.writeln( listType + startTag );
  39.    
  40.             for ( var i = 1; i <= 3; ++i )
  41.                document.writeln( "<li>List item " + i +  "</li>" );
  42.    
  43.             document.writeln( endTag );
  44.          }
  45.          else
  46.             document.writeln( "Invalid choice: " + choice );
  47.          // -->
  48.       </script>
  49.  
  50.    </head>
  51.    <body>
  52.       <p>Click Refresh (or Reload) to run the script again</p>
  53.    </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement