Kerala Plus Two Computer Science Chapter Wise Previous Questions and Answers Chapter 6 Client-Side Scripting Using JavaScript
Question 1.
“TRUE AND FALSE are used to represent boolean values”. State if the above-given statement is correct or not. [March 2016] (1)
Answer:
Correct
Note: In the case of Javascript it is not correct.
Question 2.
Develop a webpage that implements a JavaScript function that takes two numbers as input and displays their product. [March 2016] (2)
Answer:
Question 3.
Give the function in JavaScript that converts a string type data containing numbers to number type. [March 2016] (1)
Answer:
Number ()
Question 4.
a) Design a web page with form tag which accepts a number in a textbox and another textbox that should display either odd or even. Write a function in JavaScript to check whether the number is odd or even. [March 2016] (2)
OR
b) Develop a web page that accepts a number after validation and prints the factorial of it. (2)
Answer:
Question 5.
JavaScript provides a large, number of built-in functions. [March 2016]
a) Name any two of them with an example. (2)
b) The property which returns the size of the string is ………………. (1)
Answer:
a) Refer Let us Asses Question 6
b) length property eg: x = “BVM”;
alert (x;length);
Question 6.
A virtual machine for executing JavaScript code is ______ . [March 2017] (1)
Answer:
JavaScript engine.
Question 7.
Discuss about six built-in functions used in JavaScript.
Answer:
Refer Let us Asses Question 6
Question 8.
Design a procedure in JavaScript that takes two strings as input and displays the concatenated strings as output. [March 2017] (2)
Answer:
Question 9.
State whether the following statements are true or false: [Say 2017]
a) JavaScript is the only client-side scripting language. (1)
b) JavaScript is a case sensitive scripting language. (1)
c) The keyword used to declare a variable in JavaScript is VAR. (1)
Answer:
a) false
b) false (The identifiers in JavaScript are case sensitive.)
c) true.
Question 10.
Predict the output of the following code: [Say 2017]
<HTML>
<BODY>
<SCRIPT Language = “JavaScript”>
var i, s =0;
for (i=1; i<=10; i+=2)
s+=i;
document.write(“sum=”+s);
</SCRIPT>
</BODY>
</HTML> (2)
Answer:
The output is 25 (The sum of odd numbers less than 10)
Plus Two Computer Science Chapter Wise Practice Questions Chapter 6 Client-Side Scripting Using JavaScript
Question 1
Develop a web page to display the following screen. (3 Marck)
User can enter a number in the first text box. On clicking the show button, product of all numbers from 1 to the entered limit should be displayed in the second text box.
Answer:
Question 2.
Develop a web to display the following screen (5 Mark)
clicking the show button, Even or Odd should be displayed in the second text box depending on whether the number is even or odd.
Answer:
Question 3.
Develop a web page to display the following screen. (5 Mark)
The user can enter an age in the text box. If the user enters an alphabet, instead of a number in the text box, on clicking the show button, it should display a message “Invalid Age” to the user. Otherwise it should display a message “Correct Data”.
Answer:
Question 4.
Develop a login page as shown in the following figure. (5 Mark)
The page must contain one text box for entering the username and one password box for entering the password. The user name must contain at least 4 characters and the password must contain at least 6 characters. The first two characters in the password must be numbers. On clicking the show button, if the valid data are given in boxes, a message ‘‘Correct Data” should be displayed. Otherwise, “Wrong Data” message should be displayed.
Answer:
Question 5.
Develop a web page to implement a simple calculator. The page should have two text boxes to enter two numbers. It should also have 4 buttons to add, subtract, multiply and divide the two numbers. The answer should be displayed in a third text box on clicking the button. The web page should be as shown in the following figure. (5 Mark)
Answer:
Plus Two Computer Science Chapter Wise Assess Questions and Answers
Question 1.
Write the value of the variable z in each of the following (5 Mark)
a) var x,y,z;
x5;
y=3;
z++x—y—;
Answer:
z=6-3 = 3
Hence z = 3.
b) var xy,z;
x=”12″;
y=”13″;
z=x+y;
Answer:
z= “12” + 13 = 1213. If one of the operand is a string the two strings concatenates the strings.That is It concatenates two strings.
c) var x,y,z;
x=20;
y=8;
x %=y;
z=x++;
Answer:
x %=y means x=x%y.
that is x= 20 % 8.
i.e. x = 4.
Then z = 4. (x++ first use the value then change)
d) var x,y,z;
x=1;
y=4;
z= !(x<y);
Answer:
The answer is false.
z= !(1<4)
z = !(true)
z = false
e) var x,yz;
x=5;
y=6;
z (x>y) || (y% 2 == ());
Answer:
The answer is true.
Steps
z= (5>6) || (6%2())
= (false) || (0 == ())
= (false) || (true)
= true.
Question 2.
Predict the output of the following (5 Mark)
a) <HTML>
<BODY>
<SCRIPT Language’JavaScript’>
var i;
for(i=10;i>=1 ;i—)
document.write(i + “<BR>”);
</SCRIPT>
</BC DY>
</HTML>
Answer:
Answer:
The output is 2500.
Answer:
The output is 275.
Answer:
The output is 120 (5 factorial)
Question 3
Following is an html code segment in a web page (1 Mark)
<FORM Name=”frmStud”>
<INPUT Type-‘text” Name=”studentName”>
</FORM>
Fill in the blanks to store the value of the text box to the variable n.
varn;
n= __________;
Answer:
n=document.frmstud.studentName.value;
Question 4.
Suppose you have written a JavaScript function named check Data(). You want to execute the function when the mouse pointer is just moved over the button. How will you complete the following to do the same? (1 Mark)
<INPUTType=”button” _________ = ‘‘checkData()”>
Answer:
<INPUTType-’button” onMouseEnter= “checkData()”>
Question 5.
Explain <SCRIPT> tag and its attributes. (2 Mark)
Answer:
Scripts are small programs embedded in the HTML pages, to write scripts <SCRIPT> tag is used.
* Language attribute specifies the name of the scripting language used.
*Example:
<SCRIPT Language=”JavaScript”>
___________
</SCRIPT>
Question 6.
Write the syntax of a built-in function in JavaScript. (5 Mark)
Answer:
Built in functions(methods)
1) alert()- : This is used to display a message(dialogue box) on the screen.
eg: alert(“Welcome to JS”);
2) isNaN()-: To check whether the given value is a number or not. It returns a Boolean value. If the value is not a number(NaN) then this function returns a true value otherwise it returns a false value.
Eg:
1. isNaN(“BVM”); returns true
2. isNaN(8172); returns false
3. isNaN(“680121”); returns false
4. alert(isNaN(8172); displays a message box as false
3) tollpperCase() -: This is used to convert the text to upper case.
Eg:
var x=”bvm”;
alert(x.toUpperCase());
Output is as follows
4) toLowerCase():- This is used to convert the text to lowercase.
Eg:
var x=”BVM”;
alert(x.toLowerCase());
Output is as follows
5) charAt():- It returns the character at a particular position.
Syntax: variable.charAt(index);
The index of first character is 0 and the second is 1 and so on.
Eg:
var x=”HIGHER SECONDARY”;
alert(x.charAt(4));
Output is as follows
Eg.
var x=”HIGHER SECONDARY”;
alert(“The characters @ first position is “+ x.charAt(()));
6) length property-: It returns the number of characters in a string.
Syntax: variable.length;
Eg.
var x=”HIGHER SECONDARY”;
alert(“The number of characters is “+ x.length);
Output is as follows(note that space is a character)
Question 7.
Classify the following values in JavaScript into suitable data types. (3 Mark)
“Welcome”, “123”, “true”, 67.4, .98, false, “hello”
Answer:
Number-: 67.4 and .98 .
String -: “Welcome”, “123”, “true” and “hello”. Boolean -: false.
Question 8.
What is meant by undefined data type in JavaScript mean? (2 Mark)
Answer:
undefined -: It is a special data type to represent variables that are not defined using var.
Question 9.
Explain operators in JavaScript. (5 Mark)
Answer:
Operators in JavaScript
Operators are the symbols used to perform an operation
1) Arithmetic operators
It is a binary operator. It is used to perform addition(+), subtraction(-), division(/), multiplication(*) ,modulus(%-givesthe remainder) ,increment(++) and decrement—) operations.
Eg. If x=10 and y=3 then
x+y | x-y | x*y | x/y | x%y |
13 | 7 | 30 | 3.333 | 1 |
lfx=10then
document.write(++x); -> It prints 10+1=11
lf x=10then
document.write(x++); -> It prints 10 itself.
If x=10then
document.write(—x); It prints 10-1=9
lf x=10then
document.write(x—);-> It prints 10 itself.
2) Assignment operators
If a=10 and b=3 then a=b. This statement siets the value of a and b are same ,i.e. it sets a to 3. It is also called short hands
If X=10 and Y=3 then
Arithmetic Assignment Expression | Equivalent Arithmetic Expression | The value of X becomes |
X+=Y | X=X+Y | 13 |
X-=Y | X=X-Y | 7 |
X*=y | X=X*Y | 30 |
X/=Y | X=X/Y | 3.333 |
X%=Y | X=X%Y | 1 |
3) Relational(Comparison) operators
It is used to perform comparison or relational operation between two values and returns either true or false.
Eg:
If X=10 and Y=3 then
X<Y | X<=Y | X>Y | X>=Y | X==Y | X!=Y |
false | false | true | true | false | true |
4) Logical operators
Here AND(&&), OR(||) are binary operators and NOT(!) is a unary operator. It is used to combine relational operations and it gives either true or false
If X=true and Y=false then
X&&X | X&&Y | Y&&X | Y&&Y |
true | false | False | false |
Both operands must be true to get a true value in the case of AND(&&) operation
If X=true and Y=false then
X || X | X || Y | Y || X | Y || Y |
true | true | true | false |
Either one of the operands must be true to get a true value in the case of OR(||) operation
If X= true and Y=false then
!X | !Y |
false | true |
5) String addition operator(+)
This is also called a concatenation operator. It joins (concatenates) two strings and forms a string.
Eg:
var x,y,z;
x= “BVM HSS”;
y= “Kalparamba”;
z=x+y;
* Here the variable z becomes “BVM HSS Kalparamba’’.
Note : If both the operands are numbers then addition operator(+) produces number as a result otherwise it produces string as a result.
Consider the following
Operand 1 data type | Operand 2 data type | Operation | Resultant data type |
number | number | number | |
number | string | +(addition) | string |
string | number | string | |
string | string | string |
Eg:
1) 8(number) + 3(number)=11 (Result is a number)
2) 8 (number)+ “3″( string) = “83” (Result is a string)
3) “8” (string) + 3 (number) = “83”(Result is a string)
4) “8” (string) + “3” (string) = “83” (Result is a string)
Question 10.
Write JavaScript functions to perform the following (5 Mark)
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”.
Answer:
Question 11.
Write JavaScript code to display the length of the string “Computer”. (3 Mark)
Answer:
<HTML> <head> <title> length of a string </title> </head> <BODY> <SCRIPT Languages’JavaScript”> var str.len; str=”Computer"; len=str. length; alert('The length of the string Computer is “+len); </SCRIPT> </BODY> </HTML>
Question 12.
A web page contains a button. Write HTML code for the button which executes a function Message() on the occurrence of the following events. (2 Mark)
a) When a user clicks the mouse on the button.
b) When user moves the mouse over the button.
Answer:
a) <inputtype=”button”value=”Message”
onClick=”Message()”>
b) <input types”button” value=”Message”
onMouseEnter=”Message()”>
Question 13.
What are the advantages of writing JavaScript code in the head section of an HTML page? (2 Mark)
Answer:
Scripts can be placed inside the <HEAD> section. This method is widely accepted method. The main reason for this is that body section contains a large volume of text contents to be displayed on the web page. More over the head section is loaded before the body section.
Question 14.
Design an HTML page that contains a text box to enter the marks in a given subject. (5 Mark)
a) Write HTML code for this web page
b) Provide validations for this text box in a separate JavaScript file and link it with the HTML file. The validations are
(i) it should not be empty
(ii) it should be a number
(iii) it should be between 0 and 60.
c) List the advantages of writing the script in a separate file.
Answer:
c) We can write scripts in a file and save it as a separate file with the extension .js. The advantage is that this file can be used across multiple HTML files and can be enhance the speed of page loading.