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

Ans.  <html>

                      <head>
                          <title>String Manipulation</title>

                      </head>
                      <body text=blue>

                          <h1>String Manipulation</h1>
                          <p>Original String: “Give Gratitude Everyday”</p>

                          <button onclick=”myfunction()”>Click Here</button>
                          <p id=”answer”></p>

                          <script>

                           var str1 = “Give Gratitude Everyday”;
                           var outputElement = document.getElementById(“answer”);

                         function reverseString(str) {

                             return str.split(“”).reverse().join(“”);
                         }

                         function myfunction() {

                             var rstr1 = reverseString(str1);
                             var nstr = str1.replace(/ /g, “**”); //to replace all spaces

                             var pos = str1.indexOf(“it”);

                              var result = `Reversed String: “${rstr1}”<br>String with Spaces Re-
                                placed: “${nstr}”`;



                             if (pos !== -1) {

                                 result += `<br>Position of “it”: ${pos}`;
                             } else {

                                 result += `<br>”it” not found in the string.`;

                             }
                             outputElement.innerHTML = result;

                         }

                          </script>
                      </body>

                      </html>






                                                                                                    Practical Work   283
   280   281   282   283   284   285   286   287   288   289   290