Page 357 - Webapplication11_C11_Flipbook
P. 357

4.22 DECISION MAKING
                 Decision making in JavaScript is done by called conditional statements which decide the flow of program execution.
                 The following conditional statements are available in JavaScript:

                 Ð Ðif statement

                 Ð Ðif...else statement
                 Ð ÐNested if statement
                 Ð ÐSwitch statement
                 The if Statement

                 The if statement is the simplest conditional statement. Here, a statement or a collection of statements within the if
                 block is executed only if a certain condition or expression evaluates to true. If the condition evaluates to false, then the
                 control of execution is passed to the next statement after the if block. The syntax of the if statement is given below:

                   if (condition) {
                     //  block of code to be executed when the condition is true
                   }
                 Flow diagram:


                                                                Start







                                                                  if       False
                                                              condition




                                                              True

                                                              Statements





                                                                 Stop


                 Example:
                   <!DOCTYPE HTML>

                   <HTML>
                   <HEAD>

                   <TITLE> if statement </TITLE>
                   </HEAD>
                   <BODY>

                   <SCRIPT>
                   var num = parseInt(prompt("Enter the number: "));


                                                                                                  JavaScript Part 1  355
   352   353   354   355   356   357   358   359   360   361   362