Page 319 - Web Applications (803) Class 11
P. 319

Lab Assignment ‘n Activity                           Critical Thinking



                   Find the error in the following code and rewrite the code.
                   if(age > 18)
                   {
                   document(‘You are eligible to vote’);
                   }
                   else
                   {
                   document(‘Not eligible to vote’);
                   }


                 Nested if Statement

                 JavaScript allows the nested if statement. This means the if indented block inside another if…else indented block. The
                 second nested if indented block will run only when the first if condition evaluates to be true. The syntax of nested if
                 statement is shown below:

                   if(condition 1)
                   {
                   if(condition 2)
                   {
                   //When the condition 1 and condition 2 is true then block of code to be executed.
                   }
                   else
                   {
                   //When  the condition  1 is true and condition  2 is false  then block  of code to be
                   executed.
                   }
                 Flow diagram:




                                                   condition       True
                                                                             Statement1
                                                      1


                                                  False


                                                   condition       True
                                                                             Statement2
                                                      2


                                                  False


                                                   condition       True
                                                                             Statement3
                                                      3

                                                  False
                                                           Statements outside the if-else if-else block


                                                                      Introduction to Dynamic Websites Using JavaScript  317
   314   315   316   317   318   319   320   321   322   323   324