Page 428 - Webapplication11_C11_Flipbook
P. 428
else if (num % 3 === 0)
document.write("Fizz");
else if (num % 5 === 0)
document.write("Buzz");
else
document.write(num);
</script></body>
</html>
On running the above program, we get the following output:
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>
On running the above program, we get the following output:
426 Touchpad Web Applications-XI

