Previous Year CBSE Board Question Paper 2022-2017
CLASS XII WEB APPLICATION (SUBJECT CODE -803)
CHAPTER 3- WEB SCRIPTING – JAVASCRIPT
Answer Key of Previous Year Questions – CBSE 2022 Compartment Examination
1 – Mark Questions
1. Write the output of the following code: isNaN(4)
Answer: false
document.write(isNaN(4));
2. Write a statement to check whether 22/4 is infinite or not.
Answer: isFinite(22/4)
document.write(isFinite(22/4));
true
3. How many times will the following loop run?
while (true)
{
..
..
}
Answer: Infinite
4. Write the names of the following JavaScript operators: &&, ||
Answer: && – Logical AND, and || – Logical OR operator
2 – Marks Questions
5. Explain ternary operator for conditional expression in JavaScript with example.
Answer: Ternary Operator ( ? : ) is also known as conditional operator. Which is used to assign a value to the variable on the basis of the condition. If conditional expression is true then assign a value written in true part otherwise assign a value written in false part.
Syntax:
Variable = conditional_expression? true expression : false expression;
Example:
var x = 10 < 5 ? 10 : 5;
document.write(“Value of x :”+x);
Output:
Value of x: 5
6. Explain the following array functions of JavaScript: (a) splice( ) (b) unshift()
Answer:
(a) splice() : The Array.splice() method adds and removes array elements
Example:
var fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
// At position 2, add 2 elements, remove 1:
fruits.splice(2, 1, “Lemon”, “Kiwi”);
document.write(fruits + “<br>”);
Output:
Banana,Orange,Lemon,Kiwi,Mango
(b) unshift() : The unshift() method adds new elements to the beginning of an array. The unshift() method overwrites the original array.
Example:
fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
fruits.unshift(“Lemon”, “Pineapple”);
document.write(fruits + “<br>”);
Output:
Lemon,Pineapple,Banana,Orange,Apple,Mango
7. Give appropriate method for the following tasks to be done and also name the object to which it belongs:
(a) Method that returns the nearest integer value of the argument passed.
(b) Method to add two arrays.
Answer: (a) round( ) method , belongs to Math object.
(b) concat(), belongs to String object & Array Object
3 Marks Questions
8. Write a function in JavaScript that accepts two integer variables and return the greatest number.
Answer:
<script type=”text/javascript”>
function greatest(num1, num2)
{
maximum = num1 > num2 ? num1 : num2;
return maximum;
}
n1 = parseInt(prompt(“No1”))
n2 = parseInt(prompt(“No2”))
document.write(“Greatest Number : “+greatest(n1,n2))
</script>
9. Explain the following events in JavaScript : (a) onLoad (b) onSubmit (c) onClick
Answer:
- onLoad() : onLoad events occurs when a page loads in a browser.
- onSubmit(): onSubmit events occurs when you submit a form.
- onClick( ) : onClick events occurs when an object is clicked.
10. Write a function in JavaScript to accept the name using prompt method and display a Hello message with the name entered.
For example: If the user enteres the name “Piyush”, then the output should be:
Hello Piyush
Answer:
<script type=”text/javascript”>
function Hello()
{
name = prompt(“Enter Name :”);
document.write(“Hello “, +name);
}
Hello()
</script>
4 Marks Questions
11. Write a program in JavaScript to accept the marks of a student in three subjects and find the percentage. Maximum marks for each subject is 100.
Answer:
<!DOCTYPE html>
<html>
<head>
<title>Program to find Percentage </title>
</head>
<body>
<script type=”text/javascript”>
x = parseInt(prompt(“Marks 1 “));
y = parseInt(prompt(“Marks 2 “));
z = parseInt(prompt(“Marks 3 “));
total = x + y + z;
percentage = total / 300 * 100;
document.write(“Marks 1 : ” +x + “<br>”);
document.write(“Marks 2 : ” +y + “<br>”);
document.write(“Marks 3 : ” +z + “<br>”);
document.write(“Total Marks :”+ total + “<br>”);
document.write(“Percentage : ” + Math.round(percentage) + “%” + “<br>”);
</script>
</body>
</html>
12. Predict the output of the following:
<html>
<body>
<script>
x = 10 + 4;
y = “2” + 2;
z = “Hello” + 4;
s = 10 % 4;
document.write(x + “<br>” + y + “<br>” + z + “<br>” + s)
</script>
</body>
</html>
Answer:
14
22
Hello4
2