Page 427 - Webapplication11_C11_Flipbook
P. 427

case 1:
                                    document.write("Good");
                                    break;
                                  case 2:
                                    document.write("better");
                                    break;
                                  case 3:
                                    document.write("best");
                                    break;
                                  default:
                                     document.write("invalid");
                          }
                        </script>
                        </body>
                        </html>
                      On running the above program, we get the following output:




































                   26.   Write JavaScript code that takes a number and displays “Fizz” if the number is divisible by 3, “Buzz” if the num-
                      ber is divisible by 5, and “FizzBuzz” if the number is divisible by both 3 and 5. If the number is not divisible by
                      either 3 or 5, display the number itself.

                  Ans.  <html>
                      <body text="blue">
                      <script>

                      var num=15;
                      if (num % 3 === 0 && num % 5 === 0)
                          document.write("FizzBuzz");

                                                                                                     Practical Work  425
   422   423   424   425   426   427   428   429   430   431   432