Page 432 - Webapplication11_C11_Flipbook
P. 432

31.   Write JavaScript code to accept 5 numbers from the user. Calculate and display the largest number from the 5
                   numbers entered.

               Ans.  <html>
                   <body text="blue">
                   <script>
                   var max=0;

                   for (var i = 1; i <= 5; i++) {
                     var num = parseInt(prompt("Enter number " + i + ": "));
                     document.write("<br>You entered: " + num);
                     if (num > max)
                       max = num;

                   }
                   document.write("<br>The largest number is: " + max);
                   </script>
                   </body>

                   </html>
                   On running the above program, we get the following output:




















































                430   Touchpad Web Applications-XI
   427   428   429   430   431   432   433   434   435   436   437