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

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>
                   Output:




















































                386   Touchpad Web Applications-XI
   383   384   385   386   387   388   389   390   391   392   393