3-Print Exercise
3-Print Exercise
I Chapter at a Glance
Types of Scripting: •
CUont Sid" Scripting 4r Server SidIoSc'ripting.Differenre
between Client Side and Serv!'>rSide Stripting
[ 3.30bje<\s in
)avaStript
T
1
•
DOM (l)ocQment Qbject Modell: •
o.,iiniIion, Method and Properly of OOM obit"'t
Window Objecl : •
Definition, Method and I'toperty
• of Window object,
:P«)perly Jike head, titl", URL, bod)l, bllg, Propert}' like n~=, lot,ti'iol'l, document, status, closed,
Methedslike writeO, writoln(), g"tElemenlByldO Melhod like ilIlerl(j,confirm{i. promptO, opent), dQ$<>(j,
:wIth e~ample;;. blur{), tocus{), pdl'lt(), setTirneQulO with e~mllpl~
3.1 Introduction
1~ is an interpreted scripting language.
Ans. : JavaScript
2. . ; is a set of instructions used to produce various kinds of outputs.
Ans. : Program
3. The programs in javaScript language are called .
Ans. : Scripts . ,
4'. .. is an object oriented scripting language and supports event based
programming facility.
Ans. : JavaScript
5. .. is platform independent scripting language.
Ans.: JavaScript
6. .. is knows as Universal client side scripting language.
Ans.: JavaScript
7. In ~ scripting the script resides on the client computer.
Ans. : Client side
8. In scripting the script resides on web server.
Ans. : Server side
9. .. scripting does not need any server interaction.
Ans. : Client side
10. .. ~ scripting communicates to the server.
Ans. : Server side
11. .. scripts 'are used for validation purpose.
Ans. : Client side.
12. .. scripts requires web browser as on 'interface.
Ans. : Client side
13. .. , scripts requires web server software to execute.
Ans. : Server side
14. .. is a JavaScript based open source frontend web framework
developed for single page application.
Ans. : Angular JS
15. .. is JavaScript based framework for building interactive user
interface.
Ans.: Vue Js.
Tf'Sfnformation Technology (Science) 3-3 Advanced JavaScript
3.30bjeds in JavaScript
23. The keyword is used to create new object in JavaScript.
Ans. : new
24. An :..•........ can group data together with functions needed to manipulate
it.
Ans.: Object
25. All tangible things are known as .
Ans. : Objects
26. DaM stands for : .
Ans. : Document Object Model
27. The way in which HTML document content IS accessed and modified is called as
,.
TPS Information Technology (Science) 3-9 Advanced JavaScript
3.1 Introduction
1. JavaScript is an involved scripting language.
Ans.: False
2. An interpreted language is a. type of programming. language that executes its
instructions directly without compiling machine language.
Ans. : True
TPS Information Technology (Science) 3~10 Advanced JavaScript
21. Client side scripting does not need any server interaction.
Ans. ::J'rue
22. PHP, ASP.net etc are server side scripting languages.
Ans. : True
23. Client side scripts are generally used for validation purpose.
Ans.: True
37; Properties and methods of object are accessed with "," Operator.
Ans. : True
38. JavaScript supports 4 types of objects.
Ans.: False
39. JavaScript gives facility to create user defined objects.
Ans.: True
40. The new keyword is used to create new object in JavaScript.
Ans.: True
41. DOM stands for Document Original Model. .
Ans.: False
42. The way in which HTML document content is accessed and modified is ~called as
DOM.
Ans, : True
43. Head property of DOM object returns the <head> element of the document:
Ans.: True
44. Title property is DOM object returns the name of the document.
Ans.: False
45. URL property ofDOM object returns full URL of the HTML document.
Ans. : True
46. Body property of,DOM object returns <body> elements respectively.
Ans. : True
47. writet) method of DOM object write Java script code to a document.
Ans. : True
48. writelnO method is same as write ( ) method of DOM object.
Ans.: False
49. writelnt) method of DOM object adds a new line character after each statement.
Ans. : True
50. The outerHTML property is used to change any HTML element.
Ans.: False
51. window object is parent object of all other objects-.
Ans.: True
52. An object of window is created automatically by the browser.
Ans.: True
53. name property of window object sets or returns the name of a window.
Ans. : True
54. location property of window object returns a' Boolean value indicating whether a
window has been dosed or not.
Ans. : False
TPS Information Technology (Science) 3-13 Advanced JavaScript
55. document property of window object returns the document object for the window.
Ans. : True
56. . status property of window object sets the name of a window.
Ans.: False
57. alertrjmethod of window object displays the alert box containing message with ok
button.
Ans, :True
58. promptt) method of window object displays a dialog box to set output for the user.
Ans.: False
59. confirmf) method of window object displays the confirm dialog box containing
message with ok and cancel button:
Ans. : True
60. open( ) method of window object removes the focus from the current window.
Ans.: False
61. closet) method of window object closes the current window.
Ans.r True
62. blurt) method of window object removes focus from the current window.
Ans. : True
63. focusi) method of window object removes focus from the current window.
Ans.: False·
64. printO method of window object prints the content of current window .
. Ans. : True
65. setTimeoutO method of window. object calls a function after a specified number of
milliseconds.
Ans. : True
123. isFixedO method of number object returns the string that represents a number with
exact digits after a decimal point. .
Ans.: True
124. An array is an object that can store a collection of items.
Ans, : True
125. Arrays are used to store single value in singlevariable.
Ails.: False
126. Items of array can be accessed by referring to its index number.
Ails. .True
127. Indexof first element of an array is one.
Ans.: False
128. marks[O] is the first element ofthe array.
Ans. : True
129. Index property of Array object represents two based index of the matching the
string.
Ans.: False
130. Length property of Array object reflects number of elements in array.
Ans. : True
131. concatO method of Array object joins two or more arrays and returns a copy of
joined array.
Ans.: True
132. copyWithinO method of Array object adds array elements within the array to and
from a specified positions,
Ans.: False
133. find 0 method of Array object returns the value of the first element in art array that
satisfies a test in testing. .
Ans, : True
134. forEachO method of Array object search-the array and returns it's position.
Ans.: False
135. indexOfO method. of Array object search the array for an element and returns its
position. . .
Ans. : True
136.' isArray() method of Array object removes element from array.
Ans.: False
137. popljmethod of Array objects removes the last element of an array and returns that
element.
Ans.: True
138. pusht) method of Array object add new elements to the end of an array and returns
the new length .
. Ans.:True
TPS Information Technology (Science) 3-18 Advanced JavaScript
J'"
TPS Information Technology (Science) 3-21 Advanced JavaScript
Ans.: (b) .
TPS Information Technology (Science) 3-22 Advanced JavaScript
39. . ; property of window object returns the location object for the
window. .
(a) Window (b) Array (c) Math (d) Document
Ana: (d)
40. ........................•........ property of window .object returns the location object for the
window.
(a) name (b) location (c) status (d) closed
Ans.: (b)
41. . property of window object sets or returns the text in the status.
bar of a window. .
(a) name (b) location (c) status (d) closed
Ans.: (e)
42. . property of window object returns a Boolean valve indicating
whether a window has been closed or not.
(a) closed (b) status (c) document (d) name
Ans.: (a)
43. .. method of window object display the alert box containing
message with OK button.
(a) opent) (b) closet) (c) .alertf) . (d) promptt)
Ans.: (c)
44. .. method of window object displays the confirm dialog box
containing message with ok and cancel button.
(a) blurt) (b) confirnu) (c) printt) (d) focust)
Ans.: (b)
45. . : method 'of window object displays a dialog box to get input from the
user.
(a) alertt) (b) operu) (c) confirmt) (d) prompn)
Ans.: (d)
46. .. method of window object opens the new window.
(a) opent) (b) closet) (c) focust) (d) blurt)
Ans.: (a)
47. ..............•........ method of window object closes the current window.
(a) operu) (b) closet) . (c) blurt) (dy' alertt)
Ans.: (b)
4·8. .. . method of window object removes focus from the current window.
(a) printt) (b) operu) (c) prompu) (d) blurt)
Ans.: (d)
TPS InformationTechnology (Science) 3-23 Advanced JavaScript
109. . ; method of Array object joins two or more arrays, and returns a copy of the
joined arrays.
(a) findj) (b) concan) (c) indexOfO (d) popt)
Ans.: (b)
110. . method of Array object copies array elements within the array, to and from
specific positions.
(a) findO· (b) search() (c) copyWithin() (d) indexOf()
Ans.: (c)
TPS Information Technology (Science) 3-29 Advanced JavaScript
111. . method of Array object returns the value of the first element in an array
that satisfies a test in testing.
(a)concatO (b) popt) (c) pushO' (d) findt)
Ans.: (d)
112. . method of Array object calls a function for each array element.
(a) concan) (b) forEachO (c)popO (d) pushf)
Ans.: (b)
113. . method of Array object search the array for an element and returns its
position. .
(a) concatt) (b) forEachO (c) indexOfO (d) popt)
Ans.: (c)
114. . method of Array object checks whether an objectis an array.
(a) findf) (b) popt) (c) forEachO (d) isArrayO
Ans.: (d)
115. . method of Array object removes the last element of an array and returns that
element.
(a) popO (b) puslu) (c) findt) (d) reverser)
- Ans.: (a)
116; method of Array object add new elements to the end of an array, and
returns the new length.
(a) popO (b) pusht) (c) sortt) (d) findt)
Ans.: (b)
117. . method of Array object reverses the order of the elements in an array.
(a) findt) (b) isArrayO (c) popt) (d) reverser)
Ans. : (d)
118. . method of Array object sorts the elements of an array.
(a) c6ncatO(b) sortt) (c) popt) (d) find 0
Ans.: (b)
-
3.1 Introduction
1. Features of JavaScript are : .
(a) It needs special software
.(b) JavaScript is light weight scripting language'
(c) Cannot create new function
(d) It is object oriented scripting
Ans. : (b), (d)
· TPS Information Technology (Science) 3-30 Advanced JavaScript
3.1 Introduction
1. Features ofJavaScript are .
(a) Need of special software (b) It can handle date and time effectively
(c) It cannot create new functions (d) It can not create new furictions
(e) It supports event based programming
(f) It is platform dependent scripting language
Ans. : (b), (c), (e)
2. Server Side Scripting .
(a) It is used as front end •
(b) Doesnot need any server interactions
. . J •
I .~~_~.4_Java~c!ipt _Events .
10. Select three correct event handlers in JavaScript .
(a) close (b) open '(c) onsubmit (d)onchange
(e) onunload (f) write
Ans. : (c), (4),(e)
(I)
A B
(1) Head - (a)- Returns title of the document
(2) Title (b) Returns <body> <img> elements
(3) URL (c) Returns URL of document
(4) Body,img (d) Returns <head> element of the document
(e) Writes expression
Ans.: (1) - (d), (2) - (a), (3) - (c), (4) -(b)
(II)
A B
(1) OOM (a) Defines logical structure of document
(2) writet) (b) Client Side Script
(3) writelnO (c) In which id property is used to find element
(4) getElementByldO (d) Writes JavaScript Code
(e) Writes JavaScript code to a document
after each statement
' .
by adding new line
-~-. - --- - --- -_ ... _-------- -- -- - - - -
A B
(1) Location (a) Sets name of the window
(2) Document (b) Returns Boolean value indicating whether a window
(3) Status (c) Returns document object of window
(4) Closed (d) Returns the text in the status bar of a window
--"-
(5) --
Name--
(e) Returnsthe location object for the window -
Ans. : (1) - (e), (2) - (e), (3) - (d); (4) '- (b);(5),- (a)
(IV)
A B
(1) Window object (a) Displays dialog box containing message with ok and
cancel. button
(2) alertf) (b) Opens the new window
(3) confirmt) (c) Displays dialog box to get input from the user
(4) promptO (d) Parent object of all 'other objects
(5)
-
opent) (e) Displays box with ok button
Ans. : (1) - (d), (2) - (e), (3) - (a), (4) - (c), (5) - (b)
TPS Information Technology (Science) 3-37 Advanced JavaScript,
(V)
i
A B I
I
(2) On focus (b) Occurs when user selects some text of an element
(4) On select (d) Occurs when user leaves field or losses focus of an element
A B
I
(1) Onsubmit (a) . Occurs when user clicks on reset button
(3) Onload (c) Occurs when document page has been unloaded or closes
(I)
.A.
-.
B
(1) Length (a) Returns the character at the specified position
(2) chartAtO (b) Returns the index of last occurrence of specified character in
given story
(3) indexOfO (c) Returns the characters you specified
(4) lastIndexOfO (d) Returns the index of the first occurrence of the character
(5) substrt) (e) Returns a number of character in a string
- - _. - - - - -- -- _ .. -- --_. - -- - -
Ans. : (1) - (e), (2) - (a), (3) - (d), (4) - (b), (5) - (c)
(II)
A B
(1) substringt) (a) Returns the characters you specified
(2) trimO (b) Converts a string into lower case
(3) toLowerCaseO (c) Returns length of string
-
(4) to UpperCaseO (d) Converts the string into Upper case
(e) Removes white spaces from both sides of a string
_
----_. --- .. -- _-
--_ ..- ----- -- ~-- -----_ ..
(1) absO (a) Returns next integer greater than or equal to a given number -,
(2) cbrtO (b) Returns the highest valued number in a list of NUmbers
(3) ceilt) (c) Returns the absolute value of a number
(4) floorO (d) .Returns the cube root of a number
(5) max() (e) Returns next integer less than or equal to a given. number
Ans, : (1) - (c),(2) - (d), (3) -(a), (4) -(e), (5) - (b)
(IV)
A B
-
(1) mirif) (a) Returns the base to the exponent power
(2) powO (b) Returns the square root of a number
(3) randomt) (c) Returns the cube root of a number
(4) sqrtO (d) Returns a random number between 0 and 1
(e) Returns the lowest valued number in a list of number'
--
(V)
A B
(1) getbateO (a) Returns the year
(2) getDayO (b) Returns the Time
(3) getFullYearO (c) Returns the day of the week
(4) getHoursO (d) Returns the hour
(e) Returns the day of the month
Ans. : (1) - (e), (2)- (c), (3) - (a), (4) - (d)
(VI)
I
A B I
A B
(1) setlvlinutesl) (a) Sets the month of a date object
(2) setMonthO (b) Set a date to a specified number of miliseconds
(3) setSecondsO (c) Returns day of the week
(4) set'I'imer) (d) Set the minutes of a date object
(e) Sets the seconds of a date object
Ans. : (1) - (d), (2) - (a), (3) - (e), (4) - (b)
TPS InformationTechnology (Science) 3-40 Advanced JavaScript
(IX)
A B
(1) MIN_VALUE (a) Represent not a Number value
(2) MAX_VALUE (b) Determines whether the given value is a Integer
(3) NaN (c) Returns the largest minimum value
(4) isInteger( ) (d) Converts string into Floating point number
(e) Returns the largest max~urn ~~ue
Ans. : (1) - (c), (2) - (e), (3) - (a), (4) - (b)
(X)
A B
(1) parseFl6atO (a) Used to create date and time values
(2) parselntl) (b) Returns the string that represents a number with exact digits
after a decimal point
(3) isFixed() (c) Converts a given string into a floating point number
(4) Date object (d) Converts the given string into integer number
Ans. : (1) - (e), (2) - (d), (3) - (b), (4) - (a)
(IX)
A B
(1) concatt) (a) Returns the value of the first element in an array that satisfies a
test .
(2) copyWithinO (b) Search the array for an element and return its position
(3) findt) (c) Calls a function for each array element
.(4) forEachO (d) Joint two or more arrays and returns a copy of joined array
(5) indexOfO (e) Copies array elements within the array, to and from specified
positions.
- -- -
Ans. : (1) .;..(d), (2) - (e), (3) - (a), (4) - (e), (5) - (b)
(XII)
A B
(1) isArrayO (a) Adds a new elements to the end of an array, and returns the new
length
(2) popt) (b) Sorts the elements of an array
(3) PushO (c) Reverse the order of the elements in an array
(4) reverset) (d) Checks whether an object is an array
(5) sort( ) (e) Removes the last element of an array, and returns the element
--- _ -- - - .. - -- -- --- -
Ans. : (1) - (d), (2) - (e), (3) -(a), (4) - (c), (5) - (b)
TPS Information Technology (Science) 3~68 Advanced JavaScript
m=rrti:
document.write(n+" X H+i+" = "+m+"<br><br>n);
</script>
</html>
6. Programto print factorial of a number, accept number from the user.
Coding:
<html>
<script type='fext/jevascript''>
var n.i.f=I:
n=promptr'Enter a Number"):
for(i=n;i>=l;i-- )
f=f*i;
J
document.writef'<brc-Factorial is "+f);
</script>
</htm1>
</script>
</html>
3. Find and display factorial of given number.
Coding:
<html>
<script type="text/javascript">
var n=4,i,f=1;
TPS Information Technology (Science) 3-72 Advanced JavaScript
,for(i=n;i>=l;i--)
{
f=f>ti;
}
document.writef'<brc-Factorial of 4 is n+f);
</script>
</html>
4. Accept any string from user and count and display number of vowels occurs in it.
Coding:
<html>
<script type=tltext/javascripttl>
var n,i,ch,cnt=O;
n=prompt(tlEnter a String"):
for(i=O;i <n.length;i ++ )
{
ch=n.charAt(i);
if(ch=='a' I I ch=='A' I Ich=='e' I I ch=='E' I Ich=='i' I I ch=='i' I I
A B
1. cellO (a) Writes HTML expression or JavaScript code to a document.
2. floorO (b) Sets focus to current window.
3: writeO (c) Removes white ~paees from both sides of string.
4; .... focusf) (d) Returns next integer greater than or equal to given number.
5. trimO (e) Returns the next integer less than or equal to given number,
Ans.: 1. - d, 2. - e, 3. - a, 4. - b, . 5. ~c
DDD