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

else if (num % 3 === 0)
                       document.write(“Fizz”);

                   else if (num % 5 === 0)
                       document.write(“Buzz”);
                   else
                       document.write(num);

                   </script></body>
                   </html>









                27.   Now, modify the above program to accept the number from the user and display the message in an alert box.

               Ans.  <html>
                   <body text=”blue”>
                   <script>
                   var num=prompt(“Enter a number”);

                   if (num % 3 === 0 && num % 5 === 0)
                       alert(“FizzBuzz”);
                   else if (num % 3 === 0)
                       alert(“Fizz”);

                   else if (num % 5 === 0)
                       alert(“Buzz”);
                   else
                       alert(num);
                   </script></body>

                   </html>
                   Output:



























                382   Touchpad Web Applications-XI
   379   380   381   382   383   384   385   386   387   388   389