Page 192 - Web Applications (803) Class 12
P. 192

Flow diagram:

                                                      Start




                                                        if          False
                                                    condition


                                                          True

                                                                         else
                                                   Statements
                                                                      statements




                                                      Stop

              Example:

                  <html>
                  <body>
                  <script>
                  var number = 21;
                  if (number%2==0)
                    document.write("Even Number");
                  else
                    document.write("Odd Number");
                  </script>
                  </body>
                  </html>
              Output of the preceding program is as follows:










              As seen in the above example, the block of code in the else block is executed if the condition is false. However,
              if the first condition is false then the else if statement can be used to specify a new condition as shown:

              Syntax:
                  if (condition1) {
                    //  block of code is executed if condition1 is true
                  } else if (condition2) {
                    //  block of code is executed if the condition1 is false and condition2 is
                      true
                  } else {
                    //  block of code is executed if the condition1 is false and condition2 is
                      false
                  }
                190   Touchpad Web Applications-XII
   187   188   189   190   191   192   193   194   195   196   197