In Association with Amazon.in   Flipkart

Friday, July 12, 2013

JavaScript Switch Case Example

Switch Case : Switch is used to switch to the required block of the code depending on the value given to it.

Example :

<html>
          <head>
                   <script>
                   a = prompt('Enter any number');
                   a = parseInt(a);
                   switch (a)
                             {
                                case 1:
                                      document.write("Monday");
                                     break;
                             case 2:
                                      document.write("Tuesday");
                                      break;
                             case 3:
                                      document.write("Wednesday");
                                      break;
                             case 4:
                                      document.write("Thursday");
                                      break;
    case 5:
                                      document.write("Friday");
                                     break;
                             case 6:
                                      document.write("Saturday");
                                      break;
                             case 0:
                                      document.write("Sunday");
                                      break;
                             default:
                             document.write("Invalid input");
                             }
                   </script>
          </head>      
          <body>
          </body>
</html>


No comments:

Post a Comment


Related Posts Plugin for WordPress, Blogger...