Page 274 - Web_Application_v2.0_C12_Fb
P. 274

}
                    </SCRIPT>
                    </HEAD>
                    <BODY>
                    <H2>Check if a Number is Even or Odd</H2>
                    <LABEL>Enter a number:</LABEL>
                    <INPUT TYPE="number" ID="number">
                    <BUTTON ONCLICK="checkEvenOdd()">Check</BUTTON>
                    <P id="output"></P>
                    </BODY>
                  8.  Write JavaScript statements for the following:
                    i.  To search “sat” in the string “Humpty Dumpty sat on a wall” and display it on the webpage.
                    ii.  Perform the following actions on an array col containing the following: [“red”, “green”, “blue”]
                       a.  Add “silver” to the array col
                       b.  Join array col to another array fruits containing [“apple”, “orange”]

                       c,  Sort the array col
                       d.  Display the array col in reverse
               Ans.  i.  var str1 = "Humpty Dumpty sat on a wall";
                      var pos = str1.search("sat");
                      document.write(pos);
                     ii.  const col = ["red", "green", "blue"]
                       a.  col.push("silver");
                       b. const fruits = ["apple","orange"]

                        const new_arr = col.concat(fruits);
                       c. col.sort();
                       d. col.reverse();


              C.   Competency-based/Application-based questions.                              21 st  Century   #Critical Thinking
                                                                                                  Skills
                  1.   A JavaScript array is initialized as follows:
                     even=[2,4,6,8,10];

                     Write the status of the array after each of the following operations:
                    i.  even.shift();
                    ii.  even.pop();
                    iii.  even.push(12);
                    iv.  even.unshift(100);
               Ans.  i.  4,6,8,10
                     ii.  4,6,8
                     iii. 4,6,8,12
                     iv.  100,4,6,8,12
                  2.   Abhimanyu wants to print his name using JavaScript. However, he noticed that it was printed in lowercase. How
                    can he change it to uppercase?
               Ans.  Abhimanyu can use the toUpperCase() method in JavaScript to convert his name to uppercase.
                     For  example:

                    var name = "abhimanyu";
                    var upperCaseName = name.toUpperCase();
                    document.write(upperCaseName);
                272   Touchpad Web Applications (Ver. 2.0)-XII
   269   270   271   272   273   274   275   276   277   278   279