Page 384 - Web_Application_v2.0_C12_Fb
P. 384

processarray(arr1)
                   </SCRIPT>
                   </PRE>

                   </BODY>
                   </HTML>
                    Output of the preceding code is as follows:























                16.   Create a webpage with the following specifications:

                    Consider the following code:

                    var colors = ["Red", "Green", "Blue", "Yellow"];
                   var shapes = ["Circle", "Square", "Triangle"];
                    Write JavaScript code to:
                    • Add the item "Purple" to the beginning of the colors array using the unshift() method.

                    • Join the colors array elements into a string using the join() method.
                    • Delete the second element from the colors array using the delete operator.
                    • Concatenate the shapes array to the colors array using the concat() method.

                Ans.  <!DOCTYPE html>
                   <HTML>

                   <HEAD>
                   <TITLE>Array Operations</TITLE>
                   </HEAD>
                   <BODY>
                   <H2>Array Operations</H2>
                   <BUTTON onclick="performOperations()">Perform Operations</BUTTON>
                   <DIV id="result"></DIV>
                   <SCRIPT>
                   function performOperations() {
                   var colors = ["Red", "Green", "Blue", "Yellow"];
                   var shapes = ["Circle", "Square", "Triangle"];

                   var colorsString = colors.join(", ");


                382   Touchpad Web Applications (Ver. 2.0)-XII
   379   380   381   382   383   384   385   386   387   388   389