Page 424 - Webapplication11_C11_Flipbook
P. 424

23.   To check if the given number is lucky or not, if the given number is greater than zero and is even, then print
                   ‘Lucky number’ else print ‘Not a lucky number’.

               Ans.  <!DOCTYPE html>
                   <html>

                   <head>
                     <title> Nested if Statement </title>
                   </head>

                   <body>
                   <script>
                     var number = parseInt(prompt("Enter a number: "));
                     if(number > 0)
                     {
                   if(number % 2 ==0)
                             {
                                    document.write("Lucky number");
                             }
                             else
                             {
                                    document.write("Not a lucky number");
                             }

                422   Touchpad Web Applications-XI
   419   420   421   422   423   424   425   426   427   428   429