Page 281 - Web Applications (803) Class 12
P. 281

function display() {

                                  for (var i = 40; i <= 60; i=i+2) {
                                      document.write(i+”--”);

                                      }
                                  }

                          display();         //function call

                      </script>
                      </body>
                      </html>
                       Output:



























                   14.  Write JavaScript code to extract “apple” from the string “pineapple”.

                  Ans.  <html>

                      <head>
                          <title>Working with strings</title>

                      </head>
                      <body text=blue>

                      <h1>Extracting a substring from the string “pineapple”</h1>
                      <script>

                      var str1 = “pineapple”;
                      var nstr = str1.substring(4, 9);
                      document.write(“The extracted string is “+”<u>”+nstr+”</u>”);

                      </script>

                      </body>
                      </html>



                                                                                                    Practical Work   279
   276   277   278   279   280   281   282   283   284   285   286