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

<p id=”result”></p>

                       <script>
                           function calculate() {

                               var radius = parseFloat(document.getElementById(“radius”).value);
                               var choice = document.getElementById(“calculation”).value;

                               var answer = document.getElementById(“result”);
                               var result;

                               if (choice === “area”) {
                                   result = 3.14 * radius * radius;

                               } else if (choice === “circumference”) {
                                   result = 2 * 3.14 * radius;

                               } else {
                                   result = “Please select a calculation.”;
                               }

                                answer.textContent  =  (typeof  result  ===  ‘number’)  ?  result.
                                   toFixed(2) : result;

                           }
                       </script>
                   </body>

                   </html>
                    Output:
























                17.  Consider the string “Give Gratitude Everyday”. Write a function in JavaScript which performs the following tasks:

                    a. Reverses the string and displays it
                    b. Replaces all spaces in the string with “**”. Display the new string.
                    c. Find the position of the first occurrence of “it” and display it.





                282   Touchpad Web Applications-XII
   279   280   281   282   283   284   285   286   287   288   289