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

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”);
                             }

                378   Touchpad Web Applications-XI
   375   376   377   378   379   380   381   382   383   384   385