
JavaScript Part 2 Class 12 Web Application Code 803 NCERT Book Solution
I. Multiple Choice Questions
1. Which of the following statements is not true for JavaScript:
a. JavaScript is a compiled language.
b. In JavaScript an interpreter in the browser reads over the JavaScript code.
c. Any error found in the code, will stop the further execution of the program.
d. JavaScript can be implemented using tags.
2. A script cannot be placed
a. In the body of the page
b. In the header of the page
c. In a file with extension .js
d. In a file with extension .css
3. Which of the following is an advantage of JavaScript?
a. It can be used for client-side and server-side i.e. front end and back end.
b. It runs on multiple platforms and devices.
c. It is supported by all browsers.
d. All of the above.
4. Which of these is not a Primitive Data Type in JavaScript?
a. Boolean
b. Undefined
c. Arrays
d. Strings
5. In JavaScript adding a number and a string will return ______.
a. a string
b. a number
c. NaN
d. None of these
6. Which of the following cannot be a variable?
a. _new
b. y24
c. Val
d. 5g
7. Which of the following statements is not true for Variables in JavaScript?
a. Variables in JavaScript can be defined using the keyword var.
b. The equal to (=) sign is used to assign a value to a variable.
c. We cannot assign null to a variable.
d. A variable can be undefined.
8. Which of the following is an Arithmetic operator?
a. +=
b. ==
c. – –
d. *=
9. When we use a comparison operator the datatype of the output is always:
a. Integer
b. Boolean
c. NaN
d. Undefined
10. What will be the value returned by the following expression?
34 && -10
a. true
b. false
c. 34
d. -10
11. What will be the value returned by the following expression?
0 || -20
a. true
b. false
c. -20
d. 0
12. Which of the following statements is not true for function arguments/parameters?
a. Function parameters are listed between parenthesis ( ).
b. The number of function parameters is fixed.
c. Function arguments are the values that the function receives when it is called.
d. The arguments (parameters) act as local variables within the function.
13. In JavaScript, the definition of a function starts _______.
a. with the return type, function keyword, function name and parentheses.
b. with the function keyword, function name and parentheses.
c. with the return type, function name and parenthesis.
d. with the function name, parenthesis and return type.
14. For the provided JavaScript code, which of the following is the correct output?
var values=[4,5,6,7]
var ans=values.slice(1);
document.write(ans);
a. Error
b. 5, 6, 7
c. 4, 5, 6,
d. 4, 5, 6, 7
15. What will typeof(null) return/output?
a. object
b. null
c. undefined
d. nothing
16. For the JavaScript code provided, which of the following is the correct output?
var values = [“Three”, “Two”, “One”];
var ans=values.shift();
document.write(ans);
a. One
b. Three
c. Two
d. error
17. Of the following, which method of the Array object is used to extend an array by one or more members and return the array’s new length?
a. splice()
b. unshift()
c. sort()
d. toString()
18. Out of all the built-in methods, which one is used for removing the last element from an array and return it?
a. pop()
b. last()
c. get()
d. shift()
19. Which event occurs when a webpage has finished loading the page?
a. onload
b. onready
c. onloaded
d. unload
20. The syntax for replaceAll( ) is______.
a. string.replaceAll(searchValue, newValue)
b. string.replace(searchValue, newValue)
c. string.replaceall(searchValue, newValue)
d. None of the above
21. What will the following JavaScript code snippet output?
var x = “Hello, Include Hello”;
document.write(x.slice(-13, -1))
a. IncludeHelp!
b. IncludeHelp
c. ValueError
d. Hello,
22. What will the following JavaScript code snippet output?
var myArray = [‘h’, ‘e’, ‘l’, ‘l’, ‘o’];
document.write(myArray[0]);
document.write(myArray[1]);
a. undefined
b. he
c. ValueError
d. TypeError
23. What will the following JavaScript code output?
document.write(Math.round(117.5));
a. 117.5
b. 117
c. 118
d. 117.00
24. Which of the following cannot be an output for
document.write(Math.random()*10)
a. 8.49259898
b. 1.78925374
c. 0
d. 10
25. What happens when a user changes the content of a textbox in the following?
<input type=”text” onchange=”myFunction()”>
a. The user enters the content in the text box.
b. The user gets a message to change the content.
c. The function myFunction( ) gets invoked.
d. The user cannot change the content.
JavaScript Part 2 Class 12 Web Application Code 803 NCERT Book Solution
II. List the Built-in function for each of the Following:
1. A function to take user input as string.
Ans: prompt()
2. The function used to convert to an integer.
Ans:
3. A function to convert to a floating-point number.
Ans: parseFloat( )
4. A function to check if something is Not a Number.
Ans: isNaN()
5. Used to display data or a message in a box on the window.
Ans: alert( )
III. Write the events for the following:
1. As soon as the user presses and releases the key.
Ans: Event: keydown
Event Handler: onkeydown
2. After the browser has finished loading the page.
Ans: Event: load
Event Handler: onload
3. When an individual edits the form element’s value.
Ans: Event: change
Event Handler: onchange
4. When the mouse pointer leaves an element.
Ans: Event: mouseout
Event Handler: onmouseout
5. When the mouse pointer comes over the element.
Ans: Event: mouseover
Event Handler: onmouseover
JavaScript Part 2 Class 12 Web Application Code 803 NCERT Book Solution
IV. What will be the output of the following codes.
Que 1.
<!-- Question 1 -->
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
var x=170;
function myFunction()
{
var x=45;
document.getElementById('demo1').innerHTML= x;
}
document.getElementById("demo2").innerHTML= x+20;
myFunction();
</script>
</body>
</html>
Output:

Que 2.
<!-- Question 2 -->
<!DOCTYPE html>
<html
<body>
<script>
lang1=['java','rust','ruby']
lang2=['haskell','python']
lang1=lang1.concat(lang2)
lang1.sort()
lang1.reverse()
document.write(lang1)
</script>
</bodv>
</html>
Output: rust,ruby,python,java,haskell
Que 3.
<!-- Question 3 -->
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
var x = 55;
var y = 15;
function myFunction()
{
var x = 100;
var y = 40;
x++;
return x+y ;
}
document.getElementById("demo2").innerHTML= x+y;
document.getElementById("demo1").innerHTML = myFunction();
</script>
</body>
</html>
Output:

Que 4.
<!-- Question 4 -->
<!DOCTYPE html>
<html
<body>
<p id="Far"></p>
<p id="Cel"></p>
<script>
function toCelsius(temp) {
return (5/9) * (temp-32);
}
function toFarhenheit(temp){
return (9/5) * temp+32;
}
document.getElementById("Far").innerHTML = toFarhenheit(18);
document.getElementById("Cel").innerHTML = toCelsius(32);
</script>
</body>
</html>
Output:

Que -5.
<!-- Question 5 -->
<html>
<body>
<script>
x = Math.max(66.7,81.9,-100.5);
y = Math.min(66.7,81.9,-100.5);
z = Math.ceil(x+y);
document.write("x = "+x + "<br>");
document.write("y = "+y + "<br>");
document.write("z = "+z + "<br>");
</script>
</body>
</html>
Output:

Que 6.
<!-- Question 6 -->
<html>
<body>
<script>
var y = 0;
var p = parseInt(prompt("Enter a no."));
function checkprime(n) {
for(var x = 2;x < n; x++) {
if (n % x == 0)
{
document.write ("The number is not prime"+"<br>");
y = 1
break;
}
}
if(y == 0) {
document.write ("The number is prime"+"<br>");
}
}
checkprime(16);
checkprime(23);
</script>
</body>
</html>
Output:


JavaScript Part 2 Class 12 Web Application Code 803 NCERT Book Solution
V. What is the syntax or logical Error in the following codes? Rewrite the code with the correct syntax and underline the errors.
Que 1.