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

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  381
   378   379   380   381   382   383   384   385   386   387   388