Dave Partner

Javascript Tutorial 19 Switch Statements

  • 0 Replies
  • 155 Views

0 Members and 1 Guest are viewing this topic.

*

Offline Dave Partner

  • Administrator
  • Full Member
  • *****
  • 116
    • View Profile
Javascript Tutorial 19 Switch Statements
« on: December 30, 2016, 04:48:36 AM »

<html>
   <head>
      <title></title>
   </head>
   <body>
      <script type="text/javascript" >
         /*
         
         var x = 20;
         
         if(x == 20){
            document.write("X is equal to 20, hurray!");
         }else if(x = 30){
            document.write("X is equal to 30, hurray!");
         }else if(x > 30){
            document.write("X is greater than 30, hurray!");
         }else{
            
         }
         
         SWITCH STATEMENTS
         
         
         switch (expression){
                  case condition 1: statement(s)
                  break;
                  
                  case condition 2: statement(s)
                  break;
                  ...
                  
                  case condition n: statement(s)
                  break;
                  
                  default: statement(s)
               }
         */
         
         var x = 20;
         
         switch (x){
                  case 10: document.write("x = 10");
                  
                  
                  case 20:  document.write("x = 20");
                  
                  
                  case 30:  document.write("x = 30");
               
                  
                  default:  document.write("x is none of the above");
               }
               
               
      </script>
   </body>
</html>