Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 93 - 2625 PortGPt V2.1
P. 93

    Program 7: Write the program to select the subject by user using switch statement.

                     <!DOCTYPE HTML>

                     <HTML>
                     <HEAD>
                         <TITLE> Switch Statement </TITLE>

                     </HEAD>
                     <BODY>
                     <SCRIPT>

                       var choice = parseInt(prompt("Please select the Subject: Enter 1 for
                     Hindi / 2 for English"));
                       switch(choice)

                       {
                            case 1:
                               document.write("You selected Hindi");
                               break;

                            case 2:
                               document.write("You selected English");

                               break;

                            default:

                               document.write("You selected wrong subject");
                       }
                     </SCRIPT>

                     </BODY>
                     </HTML>
                     On running the above program, we get the following output:

                                                                                     Conditional Statements in JavaScript  91

| 88 89 90 91 92 93 94 95 96 97 98 |