Pageviews

Sunday, 28 July 2019

+2] 6. Client Side Scripting Using JavaScript - Solved Questions from text book



            Chapter 6. Client Side Scripting Using JavaScript

((+2 Computer Application / Computer Science ,  
Text book Questions and Answers)



1. Name an attribute of <SCRIPT> tag

Ans. Language

2. In JavaScript ________ function is used to print a text in the body section of an HTML page.

Ans. document.write()

3. ________ is the value given to the language attribute of <SCRIPT> tag to specify that the code follows is JavaScript code.

  Ans. javascript

4. What is the use of JavaScript engine?

     The script code is interpreted at runtime by the JavaScript engine. Every browser has a JavaScript engine. JavaScript engine is a virtual machine for executing JavaScript code. When the browser sees a JavaScript code, it is passed to the script engine for processing. The script engine executes the code. If an HTML page does not contain any JavaScript code, the browser alone is able to render the HTML page.

5. State whether the following statements are true or false

  a. Java Script is the only client side scripting language.----------True

 b.<SCRIPT>  tags  is used to include client side scripting language in an HTML page.----------True

c. An HTML file can contain only one <SCRIPT> tag in it.----------True

d. We can mix JavaScript code with HTML code----------

e. The JavaScript code must be placed within<SCRIPT>and </SCRIPT>  tags.----------True

 f. Every JavaScript statement ends in a semicolon.----------true

6.  Say whether the following statements are true or false:

 a. A function is automatically executed when the browser opens the web page.---------False

 b. A function is usually placed in the head section of a web page.----------False

c. A function can be called any number of times. ----------True

d. Even though a function is defined within the body section, it will not be executed, if it is not called. ------------False

7. List the advantages of using functions in JavaScript.

  The biggest advantage of using a function is that if we need to execute a piece of program code more than once in a web page, the code has to be written only once within the function. We can call the function any number of times to execute it.

8.  number, string and ______ are the basic data types in JavaScript.

Ans. Boolean 

9. true is a ______ type data.

Ans. Boolean

 10. false is a ______ type data. 

Ans. Boolean

11. The keyword used to declare a variable in JavaScript is ______. 

Ans. var

12. The function used to know the type of data in JavaScript is _____. 

Ans. typeof( )

13. What is the use of % operator?

        % operator is a modulus(division remainder).That is a and b are the two operators.then a%b means a divided b and the answer is remainder.For example 6%4 = 2 is the answer.

 14. List the logical operators.

         AND(&&),OR(||) and NOT(!)

15. To select a group of statements in the program code for execution ______ or ______ control structures are used

16 . Give examples of looping statements in JavaScript. 
     Ans. For loop and while loop

17. ______ is a multi branching statement. 

Ans. Switch

18. State whether the following statements are true or false

 a. break statement is used within the switch block.-----------True

 b. If we use switch, we will be using break within it, at least once. ----------True

c. All the program codes written in if-else can be replaced by using switch.-------False

 d. All the program codes written in switch can be replaced by using if-else.-------False

 19. What is the difference between for loop and while loop?

     for loop is used to execute a group of instructions repeatedly. for loop uses a loop variable to control the number of iterations. 

The syntax of for loop is:

 for(initialisation; test_expression; update_statement)

 { 
statements;
 }

 Here initialisation is used to initialise loop variables. test_expression checks the condition and update statement is used to increment or decrement loop variables.

    while loop is a simple loop that repeatedly execute a group of statements based on a condition.

 The syntax is 

while (test_expression) 


statements;

 } 

Here the test_expression is a condition. The statements inside the loop will be executed as long as the condition remains true.

20. Write the value of the variable y in the following:

 1. x = “welcome”; 
y = x.length;                      Ans. y=7

 2. x = “WELCOME”;
 y = x.toLowerCase();       Ans. y= welcome

3. x = “Welcome”;
 y = x.toUpperCase();        Ans. y = WELCOME

 4. x = “welcome”;
 y = x.toLowerCase();          Ans. y = welcome

 5. x = “welcome”;  
y = isNaN(x);                        Ans. y = True

6. x = “welcome”;
 y = charAt(3);                        Ans. y = c


21. When will onMouseEnter event of JavaScript work?

     Occurs when the mouse pointer is moved onto an object.

 22. The property of the drop-down list  (<SELECT> element) used to get the index of the selected item is __________.

Ans.Selected index

23. Compare onKeyDown and onKeyUp events of JavaScript.

     onKeyDown Occurs when the user is pressing a key on the keyboard and onKeyUp Occurs when the user releases a key on the keyboard.

24. What is the use of Number() function?

       The Number()function converts the data into number type and assigns that number into the variable num1. In the above function, num1 and num2 are treated as number type data and hence the correct result is obtained after adding.

25. What is the advantage of placing JavaScript code just above the </BODY> tag?

    The head section of a web page is loaded before the body section. Therefore, if any function call is made in the body section, the function will be executed as the function definition is already loaded in the memory.

26. 1. Write the value of the variable z in each of the following:

 a. var x, y, z;

 x = 5; y = 3;

z = ++x - y--;                              Ans.  3 

b. var x, y, z;

 x = “12”;

 y = 13;

 z = x + y;                                       Ans. 1213

c. var x, y, z;

 x = 20;

y = 8;

 x %= y;

 z = x++;                                             Ans. 4

 d. var x, y, z;

 x = 1;

 y = 4;

z = !(x < y);                                       Ans. False

e. var x, y, z;

 x = 5;

y = 6 ;

z = (x > y) || (y % 2 == 0);                  Ans. True

27. Write JavaScript functions to perform the following

a. To check whether a variable N contains a number 

 b. To convert the string “scert” to all capitals 

 c. To convert the string “HTML” to all small letters.

d. To display a message “Welcome to functions”.

 e. To display the third character in the string “Computer”.

Answers:-

a.x = N

     y = x. isNaN( );

b.     x = "scert"
       
       y = x.ToUppercase( );

c.    x = "HTML"

        y = x.ToLowercase( );

d.  alert("Welcome to functions");

e.   x = "Computer"

       y = x. charAt( 3 );

28. Classify the following values in JavaScript into suitable data types.
                                     
                                    Answer

 “Welcome” -------------String 

 “123”      -------------- String

 “true”      -------------  String

 67.4       -------------- Number

 .98         --------------  Number

 false     --------------- Boolean

 “hello” -------------- String

30. Explain operators in JavaScript.

        Arithmetic operators,Relational operators,Logical operators,String addition operators and assignment operators.

Arithmetic operator

     +,-,*,/,%,++,-- are the arithmetic operators.

Relational  operators:

          ==,!=,<,<=,>,>= are the relational operators.

Logical operator:

      &&,||,! are the logical operators.

String addition  Operators:

       The same operator + is used to add two strings also. Adding two strings means concatenating two strings. Look at the following example code.

 var x, y;

x = “A good beginning ”;

 y = “makes a good ending.”;

 z = x + y;

 The + operator will add the two strings. Therefore the variable z will have the value A good beginning makes a good ending. The same + operator behaves differently based on the type of operands. If the operands are numbers, it will add the numbers. If the operands are strings it will concatenate the strings.
Now, predict the value of z in the following code:

var x, y;

 x = “23”;

y = 5;

z = x + y;
The answer is 235

Assignment operators

        =,+=,-=,*=,/=,%= are the assignment operators.