0% found this document useful (0 votes)
721 views276 pages

Javascript Multiple Choice Questions and Answers-Sheet 1

This document contains 55 multiple choice questions about JavaScript. It covers topics like why JavaScript and Java have similar names, what machine executes JavaScript scripts, client-side vs server-side JavaScript, JavaScript variables, tags, syntax, arrays, functions, events, objects and more. The questions are in a multiple choice format with a single correct answer listed for each.

Uploaded by

mamidi sudeep
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
721 views276 pages

Javascript Multiple Choice Questions and Answers-Sheet 1

This document contains 55 multiple choice questions about JavaScript. It covers topics like why JavaScript and Java have similar names, what machine executes JavaScript scripts, client-side vs server-side JavaScript, JavaScript variables, tags, syntax, arrays, functions, events, objects and more. The questions are in a multiple choice format with a single correct answer listed for each.

Uploaded by

mamidi sudeep
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 276

JavaScript Multiple Choice Questions and Answers- Sheet 1

1. Why so JavaScript and Java have similar name?


A. JavaScript is a stripped-down version of Java
B. JavaScript's syntax is loosely based on Java's
C. They both originated on the island of Java
D. None of the above
Ans: B

2. When a user views a page containing a JavaScript program, which machine actually executes the
script?
A. The User's machine running a Web browser
B. The Web server
C. A central machine deep within Netscape's corporate offices
D. None of the above
Ans: A

3. ______ JavaScript is also called client-side JavaScript.


A. Microsoft
B. Navigator
C. LiveWire
D. Native
Ans: B

4. __________ JavaScript is also called server-side JavaScript.


A. Microsoft
B. Navigator
C. LiveWire
D. Native
Ans: C

5. What are variables used for in JavaScript Programs?


A. Storing numbers, dates, or other values
B. Varying randomly
C. Causing high-school algebra flashbacks
D. None of the above
Ans: A

6. _____ JavaScript statements embedded in an HTML page can respond to user events such as mouse-
clicks, form input, and page navigation.
A. Client-side
B. Server-side
C. Local
D. Native
Ans: A

7. What should appear at the very end of your JavaScript?


The <script LANGUAGE="JavaScript">tag
A. The </script>
B. The <script>
C. The END statement
D. None of the above
Ans: A

8. Which of the following can't be done with client-side JavaScript?


A. Validating a form
B. Sending a form's contents by email
C. Storing the form's contents to a database file on the server
D. None of the above
Ans: C

9. Which of the following are capabilities of functions in JavaScript?


A. Return a value
B. Accept parameters and Return a value
C. Accept parameters
D. None of the above
Ans: C

10. Which of the following is not a valid JavaScript variable name?


A. 2names
B. _first_and_last_names
C. FirstAndLast
D. None of the above
Ans: A

11. ______ tag is an extension to HTML that can enclose any number of JavaScript statements.
A. <SCRIPT>
B. <BODY>
C. <HEAD>
D. <TITLE>
Ans: A

12. How does JavaScript store dates in a date object?


A. The number of milliseconds since January 1st, 1970
B. The number of days since January 1st, 1900
C. The number of seconds since Netscape's public stock offering.
D. None of the above
Ans: A

13. Which of the following attribute can hold the JavaScript version?
A. LANGUAGE
B. SCRIPT
C. VERSION
D. None of the above
Ans: A

14. What is the correct JavaScript syntax to write "Hello World"?


A. System.out.println("Hello World")
B. println ("Hello World")
C. document.write("Hello World")
D. response.write("Hello World")
Ans: C
15. Which of the following way can be used to indicate the LANGUAGE attribute?
A. <LANGUAGE="JavaScriptVersion">
B. <SCRIPT LANGUAGE="JavaScriptVersion">
C. <SCRIPT LANGUAGE="JavaScriptVersion"> JavaScript statements…</SCRIPT>
D. <SCRIPT LANGUAGE="JavaScriptVersion"!> JavaScript statements…</SCRIPT>
Ans: C

16. Inside which HTML element do we put the JavaScript?


A. <js>
B. <scripting>
C. <script>
D. <javascript>
Ans: C

17. What is the correct syntax for referring to an external script called " abc.js"?
A. <script href=" abc.js">
B. <script name=" abc.js">
C. <script src=" abc.js">
D. None of the above
Ans: C

18. Which types of image maps can be used with JavaScript?


A. Server-side image maps
B. Client-side image maps
C. Server-side image maps and Client-side image maps
D. None of the above
Ans: B

19. Which of the following navigator object properties is the same in both Netscape and IE?
A. navigator.appCodeName
B. navigator.appName
C. navigator.appVersion
D. None of the above
Ans: A

20. Which is the correct way to write a JavaScript array?


A. var txt = new Array(1:"tim",2:"kim",3:"jim")
B. var txt = new Array:1=("tim")2=("kim")3=("jim")
C. var txt = new Array("tim","kim","jim")
D. var txt = new Array="tim","kim","jim"
Ans: C

21. What does the <noscript> tag do?


A. Enclose text to be displayed by non-JavaScript browsers.
B. Prevents scripts on the page from executing.
C. Describes certain low-budget movies.
D. None of the above
Ans: A

22. If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the
paragraph?
A. "New Text"?
B. para1.value="New Text";
C. para1.firstChild.nodeValue= "New Text";
D. para1.nodeValue="New Text";
Ans: B

23. JavaScript entities start with _______ and end with _________.
A. Semicolon, colon
B. Semicolon, Ampersand
C. Ampersand, colon
D. Ampersand, semicolon
Ans: D

24. Which of the following best describes JavaScript?


A. a low-level programming language.
B. a scripting language precompiled in the browser.
C. a compiled scripting language.
D. an object-oriented scripting language.
Ans: D

25. Choose the server-side JavaScript object?


A. FileUpLoad
B. Function
C. File
D. Date
Ans: C

26. Choose the client-side JavaScript object?


A. Database
B. Cursor
C. Client
D. FileUpLoad
Ans: D

27. Which of the following is not considered a JavaScript operator?


A. new
B. this
C. delete
D. typeof
Ans: B

28. ______method evaluates a string of JavaScript code in the context of the specified object.
A. Eval
B. ParseInt
C. ParseFloat
D. Efloat
Ans: A

29. Which of the following event fires when the form element loses the focus: <button>, <input>,
<label>, <select>, <textarea>?
A. onfocus
B. onblur
C. onclick
D. ondblclick
Ans: B

30. The syntax of Eval is ________________


A. [objectName.]eval(numeriC.
B. [objectName.]eval(string)
C. [EvalName.]eval(string)
D. [EvalName.]eval(numeriC.
Ans: B

31. JavaScript is interpreted by _________


A. Client
B. Server
C. Object
D. None of the above
Ans: A

32. Using _______ statement is how you test for a specific condition.
A. Select
B. If
C. Switch
D. For
Ans: B

33. Which of the following is the structure of an if statement?


A. if (conditional expression is true) thenexecute this codeend if
B. if (conditional expression is true)execute this codeend if
C. if (conditional expression is true) {then execute this code>->}
D. if (conditional expression is true) then {execute this code}
Ans: C

34. How to create a Date object in JavaScript?


A. dateObjectName = new Date([parameters])
B. dateObjectName.new Date([parameters])
C. dateObjectName := new Date([parameters])
D. dateObjectName Date([parameters])
Ans: A

35. The _______ method of an Array object adds and/or removes elements from an array.
A. Reverse
B. Shift
C. Slice
D. Splice
Ans: D

36. To set up the window to capture all Click events, we use which of the following statement?
A. window.captureEvents(Event.CLICK);
B. window.handleEvents (Event.CLICK);
C. window.routeEvents(Event.CLICK );
D. window.raiseEvents(Event.CLICK );
Ans: A

37. Which tag(s) can handle mouse events in Netscape?


A. <IMG>
B. <A>
C. <BR>
D. None of the above
Ans: B

38. ____________ is the tainted property of a window object.


A. Pathname
B. Protocol
C. Defaultstatus
D. Host
Ans: C

39. To enable data tainting, the end user sets the _________ environment variable.
A. ENABLE_TAINT
B. MS_ENABLE_TAINT
C. NS_ENABLE_TAINT
D. ENABLE_TAINT_NS
Ans: C

40. In JavaScript, _________ is an object of the target language data type that encloses an object of
the source language.
A. a wrapper
B. a link
C. a cursor
D. a form
Ans: A

41. When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type
___________
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B

42. _______ class provides an interface for invoking JavaScript methods and examining JavaScript
properties.
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B

43. _________ is a wrapped Java array, accessed from within JavaScript code.
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: A

44. A ________ object is a reference to one of the classes in a Java package, such as
netscape.javascript .
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: B

45. The JavaScript exception is available to the Java code as an instance of __________
A. netscape.javascript.JSObject
B. netscape.javascript.JSException
C. netscape.plugin.JSException
D. None of the above
Ans: B

46. To automatically open the console when a JavaScript error occurs which of the following is added
to prefs.js?
A. user_pref(" javascript.console.open_on_error", false);
B. user_pref("javascript.console.open_error ", true);
C. user_pref("javascript.console.open_error ", false);
D. user_pref("javascript.console.open_on_error", true);
Ans: D

47. To open a dialog box each time an error occurs, which of the following is added to prefs.js?
A. user_pref("javascript.classic.error_alerts", true);
B. user_pref("javascript.classic.error_alerts ", false);
C. user_pref("javascript.console.open_on_error ", true);
D. user_pref("javascript.console.open_on_error ", false);
Ans: A

48. The syntax of a blur method in a button object is ______________


A. Blur()
B. Blur(contrast)
C. Blur(value)
D. Blur(depth)
Ans: A

49. The syntax of capture events method for document object is ______________
A. captureEvents()
B. captureEvents(args eventType)
C. captureEvents(eventType)
D. captureEvents(eventVal)
Ans: C

50. The syntax of close method for document object is ______________


A. Close(doC.
B. Close(object)
C. Close(val)
D. Close()
Ans: D

51. <script type="text/javascript">


x=4+"4";
document.write(x);
</script>

Output------?
A. 44
B. 8
C. 4
D. Error output
Ans: A

52. Is it possible to nest functions in JavaScript?


A. True
B. False
Ans: A

53. <script>
document.write(navigator.appCodeName);
</script>
A. get code name of the browser of a visitor
B. set code name of the browser of a visitor
C. None of the above
Ans: A

54. Scripting language are


A. High Level Programming language
B. Assembly Level programming language
C. Machine level programming language
Ans: A

55. Which best explains getSelection()?


A. Returns the VALUE of a selected OPTION.
B. Returns document.URL of the window in focus.
C. Returns the value of cursor-selected text
D. Returns the VALUE of a checked radio input.
Ans: C

56. Choose the client-side JavaScript object:


A. Database
B. Cursor
C. Client
D. FileUpLoad
Ans: D

57. What is mean by "this" keyword in javascript?


A. It refers current object
B. It referes previous object
C. It is variable which contains value
D. None of the above
Ans: A

58. In JavaScript, Window.prompt() method return true or false value ?


A. False
B. True
Ans: A

59. <script language="javascript">


function x()
{
document.write(2+5+"8");
}
</script>
A. 258
B. Error
C. 7
D. 78
Ans: D

60. <script type="text/javascript">


var s = "9123456 or 80000?";
var pattern = /\d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
A. 9123
B. 91234
C. 80000
D. None of the above
Ans: A
Javascript Quiz Questions and Answers-Sheet 2
1) <script type="text/javascript">
x=4+"4";
document.write(x);
</script>

Output------?
a) 44
b) 8
c) 4
d) Error output

2) <script type="text/javascript" language="javascript">


var qpt = "Qualiyt Point Technologies";
var result = qpt.split(" ");
document.write(result);
</script>
a) Quality
b) Q,u,a,l,i,t,y,P,o,i,n,t,T,e,c,h,n,o,l,o,g,i,e,s
c) Qualiyt,Point,Technologies
d) QualityPointTechnologies

3) Is it possible to nest functions in JavaScript?


a) True
b) False

4) <script>
document.write(navigator.appCodeName);
< /script>
a) get code name of the browser of a visitor
b) set code name of the browser of a visitor
c) None of the above

5) Which of the following is true?


a) If onKeyDown returns false, the key-press event is cancelled.
b) If onKeyPress returns false, the key-down event is cancelled.
c) If onKeyDown returns false, the key-up event is cancelled.
d) If onKeyPress returns false, the key-up event is canceled.

6) Scripting language are


a) High Level Programming language
b) Assembly Level programming language
c) Machine level programming language
Show Answer

7) Which best explains getSelection()?


a) Returns the VALUE of a selected OPTION.
b) Returns document.URL of the window in focus.
c) Returns the value of cursor-selected text
d) Returns the VALUE of a checked radio input.

8) <script language="javascript">
function x()
{
var s= "Good 100%";
var pattern = /\D/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error

9) <script language="javascript">
var qpt="QUALITY POINT TECHNOLOGIES";
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error

10) Choose the client-side JavaScript object:


a) Database
b) Cursor
c) Client
d) FileUpLoad

11) Are java and javascript the same?


a) NO
b) YES

12) Syntax for creating a RegExp object:


(a). var txt=new RegExp(pattern,attributes);
(b). var txt=/pattern/attributes;
Which of the above mentioned syntax will correct?
a) (a) only
b) (b) only
c) Both (a) and (b)
d) None of the above

13) <script language="javascript">


function x(z,t)
{
alert(x.length);
}
< /script>
output:
?
a) Error
b) 2
c) 1
d) 3

14) What is mean by "this" keyword in javascript?


a) It refers current object
b) It referes previous object
c) It is variable which contains value
d) None of the above

15) In JavaScript, Window.prompt() method return true or false value ?


a) False
b) True
c) None of above

16) Math. round(-20.51)=?


a) 20
b) -21
c) 19
d) None

17) <script language="javascript">


function x()
{
var s = "Quality 100%!{[!!";
var pattern = /\w/g;
var output = s.match(pattern);
document.write(output);
}
</script>
a) %,!,{,[,!,!
b) Q,u,a,l,i,t,y,1,0,0
c) Quality 100
d) Error

18) <script type="text/javascript" language="javascript">


var qpt= new Array();
qpt[0] = "WebDevelopment";
qpt[1]="ApplicationDevelopment"
qpt[2]="Testing"
qpt[3] = "QualityPointTechnologies";
document.write(qpt[0,1,2,3]);
</script>
a) Error
b) QualityPointTechnologies
c) WebDevelopment
d) WebDevelopmnet,ApplicationDevelopment,Testing,QualityPointTechnologies

19) Choose the server-side JavaScript object:


a) FileUpLoad
b) Function
c) File
d) Date

20) parseFloat(9+10)=?
a) 19
b) 910
c) None

21) <script language="javascript">


function x()
{
document.write(2+5+"8");
}
</script>
a) 258
b) Error
c) 7
d) 78

22)_________ keyword is used to declare variables in javascript.


a) Var
b) Dim
c) String
23) In Javascript, Which of the following method is used to evaluate the regular expression?
a) eval(2*(3+5))
b) evaluate(2*(3+5))
c) evalu(2*(3+5))
d) None of the above

24) <script language="javascript">


function x()
{
var s= "quality 100%";
var pattern = /\d/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) 100
b) 1,0,0
c) q,u,a,l,i,t,y,%
d) Error

25) <script type="text/javascript" language="javascript">

qpt=((45%2)==0)? "hello" : "bye";


document.write(qpt);

</script>
a) hello
b) bye
c) Error in string handling
d) None of the above

26)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern));
}
</script>
a) Error
b) POIiNT
c) Point
d) null
27) How do you create a new object in JavaScript?
a) var obj = {};
b) var obj = Object();
c) var obj=new {};
d) None of the above

28) In Javascript, What does isNaN function do ?


a) Return true if the argument is not a number.
b) Return false if the argument is not a number.
c) Return true if the argument is a number.
d) None of the above

29) If x=103 & y=9 then x%=y , what is the value of x after executing x%=y?
a) 4
b) 3
c) 2
d) 5

30) Choose the external object:


a) Date
b) Option
c) Layer
d) Checkbox

31) Choose the four symbol pairs that represent RegExp properties lastMatch, lastParent,
leftContext, and rightContext, respectively:
a) $&, $+, $`, $'
b) $+, $&, $', $`
c) $&, $~, $`, $'
d) $+, $&, $`, $'

32) Which of the following properties hold the values of the pixels of the length of the width
and height of the viewer's screen resolution?
a) screen.width and screen.height
b) Resolution.width and Resolution.height
c) screen.pixels.width and screen.pixels.height
d) ViewerScreen.width and ViewerScreen.height

33) ParseInt(“15”,10)=?
a) 15
b) 10
c) 151
d) 150

34) Which JavaScript feature uses JAR files?


a) Object signing
b) Style sheets
c) Netcaster channels
d) Image rollovers

35)How to assign a function to a variable with the JavaScript Function contructor ?


a) var f=Function("x","y","return x+y");
b) var f=Function(x,y){ return x+y;}
c) var f= new Function("x", "y", "return x + y");

36) In JavaScript, Window.alert() is used to allow user to enter something


a) True
b) False
c) None of above

37) <script language="javascript">


function x()
{
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","gi");

document.write(pattern.exec(qpt) + " ");


document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
}

</script>
a) in in In
b) in in in
c) in in null
d) in null null

38) Is Javascript has any date data type?


a) Yes
b) No

39) Math. round(-20.5)=?


a) -21
b) 20
c) -20
d) 21
40) ?_name is it valid javascript identifier?
a) Yes
b) No

41) <script language="javascript">


function x()
{
var qpt = "First come, first served";
var pattern = /first/gi;
document.write(qpt.match(pattern)[1]);
}
</script>

a) first
b) undefined
c) First
d) Error

42) (a). // , /* ...... **/


(b). / , /** ......./ , /*
(c). /*......*/ , //
(d). \*......*\ , //

In javascript, Which of the above Comments lines are used ?


a) Only (d)
b) Only (c)
c) Either (c) or (d)
d) Only (b)

43) <script language="javascript">


function x()
{
var s = "Give 100%!{[!!";
var pattern = /\W/g;
var output = s.match(pattern);
document.write(output);
}
</script>
a) ,%,!,{,[,!,!
b) G,i,v,e,1,0,0
c) Give 100
d) Error

44) Which best describes void?


a) A method
b) A function
c) A statement
d) An operator

45) <script type="text/javascript" language="javascript">


var qpt="QualityPointTechnologies";
var result =qpt.lastIndexOf("l");
document.write(result);
</script>
a) 3
b) 18
c) 17
d) 19

46) <script language="javascript">


function x()
{
var qpt = "First come, first served";
var pattern = /first/g;
document.write(qpt.match(pattern)[1]);
}
</script>
a) first
b) First
c) undefined
d) None of the above

47) <script language="javascript">


function sum(x)
{
function add(y)
{
return x+y;
}
return add;
}
function callme() { result=sum(5)(5); alert(result); }
</script>

If you call the function callme(), what will happen ?


a) 10
b) Error in calling Function
c) 5
d) None of the above

48) Who invented the javascript programming language?


a) Tennis Ritchie
b) James Gosling
c) Brendan Eich

49) <script type="text/javascript">


document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
</script>
Can you write HTML tag inside the javascript ?
a) No
b) Yes
c) Impossible

50) Which feature is supported in MSIE 3.x?


a) split()
b) document.clear()
c) join()
d) charAt()

51) How to speicfy the color of the hypertext links with JavaScript ?
a) document.linkColor="#00FF00";
b) document.LColor="#00FF00";
c) document.LinkC="#00FF00";
d) document.hyperTextLink="#00FF00":

52) <script language="javascript">


function x()
{
var qpt = "QualityPointTechnologies";
var pattern = /point/;

var output= qpt.search(pattern);

document.write("Position: " + output);


}
</script>
a) Position-7
b) Position-1
c) null
d) error

53) --------------- method returns the number of milliseconds in a date string.


a) setHours()
b) setMinutes()
c) parse()

54) ------------- converts a string to floating point numbers.


a) eval
b) ParseInt
c) ParseFloat
d) None

55) ---------------------- attempts to evaluate a string representing any javascript literals or


variables, converting it to a number.
a) eval
b) parseFloat
c) parseInt
d) None

56) Which is not an attribute of the cookie property?


a) path
b) host
c) secure
d) domain

57) How do substring() and substr() differ?


a) One is not a method of the String object.
b) substr() takes three arguments, substring() only two.
c) Only one accepts a desired string length as an argument.
d) Besides the spelling, nothing.

58) Which is not a reserved word?


a) interface
b) short
c) program
d) throws

59) In Javascript, Which of the following method is used to find out the character at a
position in a string?
a) charAt()
b) CharacterAt()
c) CharPos()
d) characAt()

60) <script type="text/javascript" language="javascript">


var qpt = "QualityPointTechnologies";
var result =qpt.substring(7,8);
document.write(result);

</script>
a) Po
b) yP
c) oi
d) P

61) How do you delete an element from an options array?


a) Set it to false.
b) Set it to null.
c) Set it to undefined.
d) Set it to -1

62) Is javaScript case sensitive ?


a) Yes
b) No

63) JavaScript RegExp Object has modifier 'i' to __________


a) Perform case-sensitive matching
b) Perform case-insensitive matching
c) Perform both case-sensitive&case-insensitive matching

64) What are the following looping structures are available in javascripts?
a) for,forecach
b) foreach,whileloop
c) do-while loop,foreach
d) for , while loop

65) Which of these is not a method of the Math object?


a) atan()
b) atan2()
c) eval()
d) acos()

66) <script type="text/javascript">


var s = "9123456 or 80000?";
var pattern = /\d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
a) 9123
b) 91234
c) 80000
d) None of the above

67) In javascript, RegExp Object Method test() is used to search a string and returns
_________
a) true or false
b) found value
c) index
d) None of the above

68) What property would you use to redirect a visitor to another page?
a) document.URL
b) window.location.href
c) .document.location.href
d) link.href

69) a.) var qpt="Quality Point Technologies";

b.) var qpt=new String("Quality Point Technologies");

Question:
In javascript, which of the above statement can used for string declaration ?

a) Either (a) or (b)


b) Only (a)
c) Neither (a) nor (b)
d) Only (b)

70) <script type="text/javascript" language="javascript">


var qpt = "QualityPointTechnologies";
var result =qpt.indexOf("Tech");
document.write(result);
</script>
a) 11
b) 12
c) 15
d) 13

71) <script language="javascript">


function x()
{
var s = "Eat to live, but do not live to eat";
var pattern = new RegExp("eat$");
document.write(pattern.exec(s));
}
</script>
a) Eat
b) eat
c) undefined
d) Eat eat

72) <script language="javascript">


function x()
{
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","g");

document.write(pattern.exec(qpt) + " ");


document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
}

</script>
a) in in In
b) in in in
c) in in null
d) in null null

73) -------------- method is used to remove focus from the specified object.
a) blur()
b) focus()
c) None

74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer

75)eval((20*4)=?
a) Nan
b) 204
c) 24
d) 80

76)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("TECHNOLOGIES","i");
document.write(qpt.match(pattern));
}
</script>
a) null
b) Technologies
c) TECHNOLOGIES
d) Error

77)Javascript is a ________ typed language.


a) tightly
b) loosely
Java Script Multiple Choice Questions and Answers-
Sheet 1
1. Why so JavaScript and Java have similar name?

A. JavaScript is a stripped-down version of Java

B. JavaScript's syntax is loosely based on Java's

C. They both originated on the island of Java

D. None of the above

Ans: B

2. When a user views a page containing a JavaScript program, which machine


actually executes the script?

A. The User's machine running a Web browser

B. The Web server

C. A central machine deep within Netscape's corporate offices

D. None of the above

Ans: A

3. ______ JavaScript is also called client-side JavaScript.

A. Microsoft

B. Navigator

C. LiveWire

D. Native

Ans: B

4. __________ JavaScript is also called server-side JavaScript.

A. Microsoft

B. Navigator
C. LiveWire

D. Native

Ans: C

5. What are variables used for in JavaScript Programs?

A. Storing numbers, dates, or other values

B. Varying randomly

C. Causing high-school algebra flashbacks

D. None of the above

Ans: A

6. _____ JavaScript statements embedded in an HTML page can respond to


user events such as mouse-clicks, form input, and page navigation.

A. Client-side

B. Server-side

C. Local

D. Native

Ans: A

7. What should appear at the very end of your JavaScript?

The <script LANGUAGE="JavaScript">tag

A. The </script>

B. The <script>

C. The END statement

D. None of the above

Ans: A

8. Which of the following can't be done with client-side JavaScript?


A. Validating a form

B. Sending a form's contents by email

C. Storing the form's contents to a database file on the server

D. None of the above

Ans: C

9. Which of the following are capabilities of functions in JavaScript?

A. Return a value

B. Accept parameters and Return a value

C. Accept parameters

D. None of the above

Ans: C

10.Which of the following is not a valid JavaScript variable name?

A. 2names

B. _first_and_last_names

C. FirstAndLast

D. None of the above

Ans: A

11. ______ tag is an extension to HTML that can enclose any number of
JavaScript statements.

A. <SCRIPT>

B. <BODY>

C. <HEAD>

D. <TITLE>

Ans: A
12. How does JavaScript store dates in a date object?

A. The number of milliseconds since January 1st, 1970

B. The number of days since January 1st, 1900

C. The number of seconds since Netscape's public stock offering.

D. None of the above

Ans: A

13. Which of the following attribute can hold the JavaScript version?

A. LANGUAGE

B. SCRIPT

C. VERSION

D. None of the above

Ans: A

14. What is the correct JavaScript syntax to write "Hello World"?

A. System.out.println("Hello World")

B. println ("Hello World")

C. document.write("Hello World")

D. response.write("Hello World")

Ans: C

15. Which of the following way can be used to indicate the LANGUAGE
attribute?

A. <LANGUAGE="JavaScriptVersion">

B. <SCRIPT LANGUAGE="JavaScriptVersion">

C. <SCRIPT LANGUAGE="JavaScriptVersion"> JavaScript


statements…</SCRIPT>
D. <SCRIPT LANGUAGE="JavaScriptVersion"!> JavaScript
statements…</SCRIPT>

Ans: C

16. Inside which HTML element do we put the JavaScript?

A. <js>

B. <scripting>

C. <script>

D. <javascript>

Ans: C

17. What is the correct syntax for referring to an external script called " abc.js"?

A. <script href=" abc.js">

B. <script name=" abc.js">

C. <script src=" abc.js">

D. None of the above

Ans: C

18. Which types of image maps can be used with JavaScript?

A. Server-side image maps

B. Client-side image maps

C. Server-side image maps and Client-side image maps

D. None of the above

Ans: B

19. Which of the following navigator object properties is the same in both
Netscape and IE?

A. navigator.appCodeName

B. navigator.appName
C. navigator.appVersion

D. None of the above

Ans: A

20. Which is the correct way to write a JavaScript array?

A. var txt = new Array(1:"tim",2:"kim",3:"jim")

B. var txt = new Array:1=("tim")2=("kim")3=("jim")

C. var txt = new Array("tim","kim","jim")

D. var txt = new Array="tim","kim","jim"

Ans: C

21. What does the <noscript> tag do?

A. Enclose text to be displayed by non-JavaScript browsers.

B. Prevents scripts on the page from executing.

C. Describes certain low-budget movies.

D. None of the above

Ans: A

22. If para1 is the DOM object for a paragraph, what is the correct syntax to
change the text within the paragraph?

A. "New Text"?

B. para1.value="New Text";

C. para1.firstChild.nodeValue= "New Text";

D. para1.nodeValue="New Text";

Ans: B

23. JavaScript entities start with _______ and end with _________.

A. Semicolon, colon
B. Semicolon, Ampersand

C. Ampersand, colon

D. Ampersand, semicolon

Ans: D

24. Which of the following best describes JavaScript?

A. a low-level programming language.

B. a scripting language precompiled in the browser.

C. a compiled scripting language.

D. an object-oriented scripting language.

Ans: D

25. Choose the server-side JavaScript object?

A. FileUpLoad

B. Function

C. File

D. Date

Ans: C

26. Choose the client-side JavaScript object?

A. Database

B. Cursor

C. Client

D. FileUpLoad

Ans: D

27. Which of the following is not considered a JavaScript operator?

A. new
B. this

C. delete

D. typeof

Ans: B

28. ______method evaluates a string of JavaScript code in the context of the


specified object.

A. Eval

B. ParseInt

C. ParseFloat

D. Efloat

Ans: A

29. Which of the following event fires when the form element loses the focus:
<button>, <input>, <label>, <select>, <textarea>?

A. onfocus

B. onblur

C. onclick

D. ondblclick

Ans: B

30. The syntax of Eval is ________________

A. [objectName.]eval(numeriC.

B. [objectName.]eval(string)

C. [EvalName.]eval(string)

D. [EvalName.]eval(numeriC.

Ans: B

31. JavaScript is interpreted by _________


A. Client

B. Server

C. Object

D. None of the above

Ans: A

32. Using _______ statement is how you test for a specific condition.

A. Select

B. If

C. Switch

D. For

Ans: B

33. Which of the following is the structure of an if statement?

A. if (conditional expression is true) thenexecute this codeend if

B. if (conditional expression is true)execute this codeend if

C. if (conditional expression is true) {then execute this code>->}

D. if (conditional expression is true) then {execute this code}

Ans: C

34. How to create a Date object in JavaScript?

A. dateObjectName = new Date([parameters])

B. dateObjectName.new Date([parameters])

C. dateObjectName := new Date([parameters])

D. dateObjectName Date([parameters])

Ans: A
35. The _______ method of an Array object adds and/or removes elements from an
array.

A. Reverse

B. Shift

C. Slice

D. Splice

Ans: D

36. To set up the window to capture all Click events, we use which of the
following statement?

A. window.captureEvents(Event.CLICK);

B. window.handleEvents (Event.CLICK);

C. window.routeEvents(Event.CLICK );

D. window.raiseEvents(Event.CLICK );

Ans: A

37. Which tag(s) can handle mouse events in Netscape?

A. <IMG>

B. <A>

C. <BR>

D. None of the above

Ans: B

38. ____________ is the tainted property of a window object.

A. Pathname

B. Protocol

C. Defaultstatus

D. Host
Ans: C

39. To enable data tainting, the end user sets the _________ environment variable.

A. ENABLE_TAINT

B. MS_ENABLE_TAINT

C. NS_ENABLE_TAINT

D. ENABLE_TAINT_NS

Ans: C

40. In JavaScript, _________ is an object of the target language data type that
encloses an object of the source language.

A. a wrapper

B. a link

C. a cursor

D. a form

Ans: A

41. When a JavaScript object is sent to Java, the runtime engine creates a Java
wrapper of type ___________

A. ScriptObject

B. JSObject

C. JavaObject

D. Jobject

Ans: B

42. _______ class provides an interface for invoking JavaScript methods and
examining JavaScript properties.

A. ScriptObject

B. JSObject
C. JavaObject

D. Jobject

Ans: B

43. _________ is a wrapped Java array, accessed from within JavaScript code.

A. JavaArray

B. JavaClass

C. JavaObject

D. JavaPackage

Ans: A

44. A ________ object is a reference to one of the classes in a Java package, such
as netscape.javascript .

A. JavaArray

B. JavaClass

C. JavaObject

D. JavaPackage

Ans: B

45. The JavaScript exception is available to the Java code as an instance of


__________

A. netscape.javascript.JSObject

B. netscape.javascript.JSException

C. netscape.plugin.JSException

D. None of the above

Ans: B

46. To automatically open the console when a JavaScript error occurs which of the
following is added to prefs.js?
A. user_pref(" javascript.console.open_on_error", false);

B. user_pref("javascript.console.open_error ", true);

C. user_pref("javascript.console.open_error ", false);

D. user_pref("javascript.console.open_on_error", true);

Ans: D

47. To open a dialog box each time an error occurs, which of the following is
added to prefs.js?

A. user_pref("javascript.classic.error_alerts", true);

B. user_pref("javascript.classic.error_alerts ", false);

C. user_pref("javascript.console.open_on_error ", true);

D. user_pref("javascript.console.open_on_error ", false);

Ans: A

48. The syntax of a blur method in a button object is ______________

A. Blur()

B. Blur(contrast)

C. Blur(value)

D. Blur(depth)

Ans: A

49. The syntax of capture events method for document object is ______________
A. captureEvents()

B. captureEvents(args eventType)

C. captureEvents(eventType)

D. captureEvents(eventVal)

Ans: C

50. The syntax of close method for document object is ______________


A. Close(doC.

B. Close(object)

C. Close(val)

D. Close()

Ans: D

51. <script type="text/javascript"> x=4+"4"; document.write(x); </script> Output--


----?

A. 44

B. 8

C. 4

D. Error output

Ans: A

52. Is it possible to nest functions in JavaScript?

A. True B. False

Ans: A

53. <script> document.write(navigator.appCodeName); </script>

A. get code name of the browser of a visitor

B. set code name of the browser of a visitor

C. None of the above

Ans: A

54. Scripting language are

A. High Level Programming language

B. Assembly Level programming language

C. Machine level programming language


Ans: A

55. Which best explains getSelection()?

A. Returns the VALUE of a selected OPTION.

B. Returns document.URL of the window in focus.

C. Returns the value of cursor-selected text

D. Returns the VALUE of a checked radio input.

Ans: C

56. Choose the client-side JavaScript object:

A. Database

B. Cursor

C. Client

D. FileUpLoad

Ans: D

57. What is mean by "this" keyword in javascript?

A. It refers current object

B. It referes previous object

C. It is variable which contains value

D. None of the above

Ans: A

58. In JavaScript, Window.prompt() method return true or false value ?

A. False B. True

Ans: A

59. <script language="javascript"> function x() { document.write(2+5+"8"); }


</script>
A. 258

B. Error

C. 7

D. 78

Ans: D

60. <script type="text/javascript"> var s = "9123456 or 80000?"; var pattern =


/\d{4}/; var output = s.match(pattern); document.write(output); </script>

A. 9123

B. 91234

C. 80000

D. None of the above

Ans: A

Javascript Quiz Questions and Answers-Sheet 2


1) <script type="text/javascript"> x=4+"4"; document.write(x); </script> Output---
---?

a) 44

b) 8

c) 4

d) Error output

2) <script type="text/javascript" language="javascript">

var qpt = "Qualiyt Point Technologies";

var result = qpt.split(" ");

document.write(result);

</script>
a) Quality

b) Q,u,a,l,i,t,y,P,o,i,n,t,T,e,c,h,n,o,l,o,g,i,e,s

c) Qualiyt,Point,Technologies

d) QualityPointTechnologies

3) Is it possible to nest functions in JavaScript?

a) True

b) False

4) <script>

document.write(navigator.appCodeName);

< /script>

a) get code name of the browser of a visitor

b) set code name of the browser of a visitor

c) None of the above

5) Which of the following is true?

a) If onKeyDown returns false, the key-press event is cancelled.

b) If onKeyPress returns false, the key-down event is cancelled.

c) If onKeyDown returns false, the key-up event is cancelled.

d) If onKeyPress returns false, the key-up event is canceled.

6) Scripting language are

a) High Level Programming lan

b) Assembly Level programming language

c) Machine level programming language

Show Answer

7) Which best explains getSelection()?


a) Returns the VALUE of a selected OPTION.

b) Returns document.URL of the window in focus.

c) Returns the value of cursor-selected text

d) Returns the VALUE of a checked radio input.

8) <script language="javascript">

function x()

var s= "Good 100%";

var pattern = /\D/g;

var output= s.match(pattern);

document.write(output);

</script>

a) Good %

b) 1,0,0

c) G,o,o,d,%

d) Error

9) <script language="javascript">

var qpt="QUALITY POINT TECHNOLOGIES";

alert(qpt.charAt(qpt.length-1));

</script>

a) P

b) E

c) S
d) Error

10) Choose the client-side JavaScript object:

a) Database

b) Cursor

c) Client

d) FileUpLoad

11) Are java and javascript the same?

a) NO

b) YES

12) Syntax for creating a RegExp object:

(a). var txt=new RegExp(pattern,attributes);

(b). var txt=/pattern/attributes;

Which of the above mentioned syntax will correct?

a) (a) only

b) (b) only

c) Both (a) and (b)

d) None of the above

13) <script language="javascript">

function x(z,t)

alert(x.length);

< /script>

output:
?

a) Error

b) 2

c) 1

d) 3

14) What is mean by "this" keyword in javascript?

a) It refers current object

b) It referes previous object

c) It is variable which contains value

d) None of the above

15) In JavaScript, Window.prompt() method return true or false value ?

a) False

b) True

c) None of above

16) Math. round(-20.51)=?

a) 20

b) -21

c) 19

d) None

17) <script language="javascript"> function x() { var s = "Quality 100%!{[!!"; var


pattern = /\w/g; var output = s.match(pattern); document.write(output); } </script>

a) %,!,{,[,!,!

b) Q,u,a,l,i,t,y,1,0,0

c) Quality 100
d) Error

18) <script type="text/javascript" language="javascript">

var qpt= new Array();

qpt[0] = "WebDevelopment";

qpt[1]="ApplicationDevelopment"

qpt[2]="Testing"

qpt[3] = "QualityPointTechnologies";

document.write(qpt[0,1,2,3]);

</script>

a) Error

b) QualityPointTechnologies

c) WebDevelopment

d) WebDevelopmnet,ApplicationDevelopment,Testing,QualityPointTechnologies

19) Choose the server-side JavaScript object:

a) FileUpLoad

b) Function

c) File

d) Date

20) parseFloat(9+10)=?

a) 19

b) 910

c) None

21) <script language="javascript">

function x()
{

document.write(2+5+"8");

</script>

a) 258

b) Error

c) 7

d) 78

22)_________ keyword is used to declare variables in javascript.

a) Var

b) Dim

c) String

23) In Javascript, Which of the following method is used to evaluate the regular
expression?

a) eval(2*(3+5))

b) evaluate(2*(3+5))

c) evalu(2*(3+5))

d) None of the above

24) <script language="javascript">

function x()

var s= "quality 100%";

var pattern = /\d/g;

var output= s.match(pattern);


document.write(output);

</script>

a) 100

b) 1,0,0

c) q,u,a,l,i,t,y,%

d) Error

25) <script type="text/javascript" language="javascript">

qpt=((45%2)==0)? "hello" : "bye";

document.write(qpt);

</script>

a) hello

b) bye

c) Error in string handling

d) None of the above

26)<script language="javascript"> function x() { var qpt =


"QualityPointTechnologies"; var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern)); } </script>

a) Error

b) POIiNT

c) Point

d) null

27) How do you create a new object in JavaScript?

a) var obj = {};

b) var obj = Object();


c) var obj=new {};

d) None of the above

28) In Javascript, What does isNaN function do ?

a) Return true if the argument is not a number.

b) Return false if the argument is not a number.

c) Return true if the argument is a number.

d) None of the above

29) If x=103 & y=9 then x%=y , what is the value of x after executing x%=y?

a) 4

b) 3

c) 2

d) 5

30) Choose the external object:

a) Date

b) Option

c) Layer

d) Checkbox

31) Choose the four symbol pairs that represent RegExp properties lastMatch,
lastParent,

leftContext, and rightContext, respectively:

a) $&, $+, $`, $'

b) $+, $&, $', $`

c) $&, $~, $`, $'

d) $+, $&, $`, $'


32) Which of the following properties hold the values of the pixels of the length of
the width

and height of the viewer's screen resolution?

a) screen.width and screen.height

b) Resolution.width and Resolution.height

c) screen.pixels.width and screen.pixels.height

d) ViewerScreen.width and ViewerScreen.height

33) ParseInt(“15”,10)=?

a) 15

b) 10

c) 151

d) 150

34) Which JavaScript feature uses JAR files?

a) Object signing

b) Style sheets

c) Netcaster channels

d) Image rollovers

35)How to assign a function to a variable with the JavaScript Function contructor ?

a) var f=Function("x","y","return x+y");

b) var f=Function(x,y){ return x+y;}

c) var f= new Function("x", "y", "return x + y");

36) In JavaScript, Window.alert() is used to allow user to enter something

a) True

b) False
c) None of above

37) <script language="javascript">

function x()

var qpt = "We are fast growing Software Company located in Chennai, India.";

var pattern = new RegExp("in","gi");

document.write(pattern.exec(qpt) + " ");

document.write(pattern.exec(qpt) + " ");

document.write(pattern.exec(qpt) + " ");

} </script>

a) in in In

b) in in in

c) in in null

d) in null null

38) Is Javascript has any date data type?

a) Yes

b) No

39) Math. round(-20.5)=?

a) -21

b) 20

c) -20

d) 21

40) ?_name is it valid javascript identifier?

a) Yes
b) No

41) <script language="javascript">

function x()

var qpt = "First come, first served";

var pattern = /first/gi;

document.write(qpt.match(pattern)[1]);

</script>

a) first

b) undefined

c) First

d) Error

42) (a). // , /* ...... **/

(b). / , /** ......./ , /*

(c). /*......*/ , //

(d). \*......*\ , //

In javascript, Which of the above Comments lines are used ?

a) Only (d)

b) Only (c)

c) Either (c) or (d)

d) Only (b)

43) <script language="javascript">

function x()
{

var s = "Give 100%!{[!!";

var pattern = /\W/g;

var output = s.match(pattern);

document.write(output);

</script>

a) ,%,!,{,[,!,!

b) G,i,v,e,1,0,0

c) Give 100

d) Error

44) Which best describes void?

a) A method

b) A function

c) A statement

d) An operator

45) <script type="text/javascript" language="javascript">

var qpt="QualityPointTechnologies";

var result =qpt.lastIndexOf("l");

document.write(result);

</script>

a) 3

b) 18

c) 17
d) 19

46) <script language="javascript">

function x()

var qpt = "First come, first served";

var pattern = /first/g;

document.write(qpt.match(pattern)[1]);

</script>

a) first

b) First

c) undefined

d) None of the above

47) <script language="javascript">

function sum(x)

function add(y)

return x+y;

return add;

function callme() { result=sum(5)(5); alert(result); }

</script>
If you call the function callme(), what will happen ?

a) 10

b) Error in calling Function

c) 5

d) None of the above

48) Who invented the javascript programming language?

a) Tennis Ritchie

b) James Gosling

c) Brendan Eich

49) <script type="text/javascript">

document.write("<h1>This is a heading</h1>");

document.write("<p>This is a paragraph.</p>");

document.write("<p>This is another paragraph.</p>");

</script>

Can you write HTML tag inside the javascript ?

a) No

b) Yes

c) Impossible

50) Which feature is supported in MSIE 3.x?

a) split()

b) document.clear()

c) join()

d) charAt()

51) How to speicfy the color of the hypertext links with JavaScript ?
a) document.linkColor="#00FF00";

b) document.LColor="#00FF00";

c) document.LinkC="#00FF00";

d) document.hyperTextLink="#00FF00":

52) <script language="javascript">

function x()

var qpt = "QualityPointTechnologies";

var pattern = /point/;

var output= qpt.search(pattern);

document.write("Position: " + output);

</script>

a) Position-7

b) Position-1

c) null

d) error

53) --------------- method returns the number of milliseconds in a date string.

a) setHours()

b) setMinutes()

c) parse()

54) ------------- converts a string to floating point numbers.

a) eval

b) ParseInt
c) ParseFloat

d) None

55) ---------------------- attempts to evaluate a string representing any javascript


literals or

variables, converting it to a number.

a) eval

b) parseFloat

c) parseInt

d) None

56) Which is not an attribute of the

a) path

b) host

c) secure

d) domain

57) How do substring() and substr() differ?

a) One is not a method of the String object.

b) substr() takes three arguments, substring() only two.

c) Only one accepts a desired string length as an argument.

d) Besides the spelling, nothing.

58) Which is not a reserved word?

a) interface

b) short

c) program

d) throws
59) In Javascript, Which of the following method is used to find out the character
at a

position in a string?

a) charAt()

b) CharacterAt()

c) CharPos()

d) characAt()

60) <script type="text/javascript" language="javascript">

var qpt = "QualityPointTechnologies";

var result =qpt.substring(7,8);

document.write(result);

</script>

a) Po

b) yP

c) oi

d) P

61) How do you delete an element from an options array?

a) Set it to false.

b) Set it to null.

c) Set it to undefined.

d) Set it to -1

62) Is javaScript case sensitive ?

a) Yes

b) No
63) JavaScript RegExp Object has modifier 'i' to __________

a) Perform case-sensitive matching

b) Perform case-insensitive matching

c) Perform both case-sensitive&case-insensitive matching

64) What are the following looping structures are available in javascripts?

a) for,forecach

b) foreach,whileloop

c) do-while loop,foreach

d) for , while loop

65) Which of these is not a method of the Math object?

a) atan()

b) atan2()

c) eval()

d) acos()

66) <script type="text/javascript">

var s = "9123456 or 80000?";

var pattern = /\d{4}/;

var output = s.match(pattern);

document.write(output);

</script>

a) 9123

b) 91234

c) 80000

d) None of the above


67) In javascript, RegExp Object Method test() is used to search a string and
returns

_________

a) true or false

b) found value

c) index

d) None of the above

68) What property would you use to redirect a visitor to another page?

a) document.URL

b) window.location.href

c) .document.location.href

d) link.href

69) a.) var qpt="Quality Point Technologies";

b.) var qpt=new String("Quality Point Technologies");

Question:

In javascript, which of the above statement can used for string declaration ?

a) Either (a) or (b)

b) Only (a)

c) Neither (a) nor (b)

d) Only (b)

70) <script type="text/javascript" language="javascript">

var qpt = "QualityPointTechnologies";

var result =qpt.indexOf("Tech");

document.write(result);
</script>

a) 11

b) 12

c) 15

d) 13

71) <script language="javascript">

function x()

var s = "Eat to live, but do not live to eat";

var pattern = new RegExp("eat$");

document.write(pattern.exec(s));

</script>

a) Eat

b) eat

c) undefined

d) Eat eat

72) <script language="javascript">

function x()

var qpt = "We are fast growing Software Company located in Chennai, India.";

var pattern = new RegExp("in","g"); document.write(pattern.exec(qpt) + " ");


document.write(pattern.exec(qpt) + " "); document.write(pattern.exec(qpt) + " "); }
</script>

a) in in In
b) in in in

c) in in null

d) in null null

73) -------------- method is used to remove focus from the specified object.

a) blur()

b) focus()

c) None

74) parseFloat(“FF2”)=?

a) 152

b) FF2

c) NaN

d) None

Show Answer

75)eval((20*4)=?

a) Nan

b) 204

c) 24

d) 80

76)<script language="javascript">

function x()

var qpt = "QualityPointTechnologies";

var pattern = new RegExp("TECHNOLOGIES","i");

document.write(qpt.match(pattern));
}

</script>

a) null

b) Technologies

c) TECHNOLOGIES

d) Error

77)Javascript is a ________ typed language.

a) tightly

b) loosely
1.Object is also called as : Component

2. which of the following is false about variable name : Variable name is not case sensitive

3. Locate first ‘X’ in the String : txt.indexof(‘X’)

4. Var mood = Joy + Happiness : Joy is added to Happiness and stored in the variable Mood

5. Var result = False && False || Truse&&True : TRUE

6. Java Script function for finding Errors: Debug

7. Built-in Object : Math

8. --------- class is used in javascript for manipulating date and time?: Date

9. An Array with Alphanumeric Index : Not Sure(Bidimensional Array)

10. Which of these is not a simple data type : Letter

11. What type of array it is [[[]]] : The Syntax is Wrong


Data types from the following options

Choose the Window object properties

If an exception is thrown

In JavaScript, Objects are passed by value


Chose the JavaScript keywords from the following options

JavaScript uses prototypal or differential inheritance

The Browser Object Model


Choose the correct option that helps to get the browser

Does JavaScript allow exception handling?

Which of the following is not a valid variable name?


How do you write a conditional statement for executing

Which event occurs when the value of an element

The shift method does not


JavaScript is also called as

When we declare a variable within a function

The ___ tag is used to draw graphics


In JavaScript, Arrays are data type

Can appear in both the <head> block and within the <block>

To create an Image rollover


Joins all elements of an array

What happens if you use parseInt() to

The setInterval method


The delete operator returns a Boolean value

The loop type always runs the enclosed code at least once

When the user is working with timing


The escape() function is responsible

Javascript ignores extra spaces

Select the javascript popup boxes from the following


Data stored in an array always have to be the same data type

Does not allow you to read or write fields


Extras!!

1. The triple equal sign === checks for equal value and equal type

2. The shift method does not removes

{javascript Array: Shift() Method. The shift() method is like the pop() method, only it works at
the beginning of the array. The shift() method pulls the first element off of the given array and
returns it. This alters the array on which the method was called}

3. Javascript is also called as

4. Alert( typeof new Date() );


5. Prototypal or different inheritance – Class based programming

6. What value is returned by a function having no return


statement when it is called in JavaScript?
The default return value is undefined for a function if no return statement is present

7. What are the different loop structure available in


JavaScript?
Following are the loop structure available in JavaScript.

 while
 do-while
 For

8. What is the difference


between == and ===operators in JavaScript?
The == operator checks only the value for equality. Whereas, === checks both the value
and the data type

9. How will you select an element in the page having id


"awesome" using JavaScript?
To select an element by id we use the document.getElementById(); method.
In the following code we are selecting the element having id "awesome".

var el = document.getElementById("awesome");
10. How will you select elements in a page having class
"super" using JavaScript?
For this we will use the document.getElementsByClassName() method.
In the following example we are selecting all the elements in the page having class "super".

var elems = document.getElementsByClassName('super');

11. How will you check if a given value is not a number in


JavaScript?
For this we can use the isNaN() method which returns true if the value passed is not a number otherwise,
false.
12. Please see the below
Operators and Datatypes – CC

Currency converter - USD – INR


<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

</style>

</head>

<body>

<div id="header">

<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">

<span>

<img align="left" src="logo.jpeg" width="120px" height="120px">

</span>

</td>

<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>

</center>

</span>

</td>
<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>

<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-left:30px">Log in</a>

</span>

</td>

</tr>

</table>

<h3>Currency Converter USD -INR(fixed Exchange)</h3>

Enter the amount in dollar($): <input type="text" id="amount"><br>

<button type="button" id="compute" align="center" onclick='mul();'>compute</button><br>

<script>

function mul()

var dol= parseInt(document.getElementById('amount').value);

var result= dol* 62.04;

var value = document.getElementById("result").innerHTML ='The INR value is Rs.'+result;

</script>

<div id="result" lable=value> </div>


</body>

</html>
Control Flow CC: -

Multiple Currency Convertor: -

<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

</style>

<script type="text/javascript">

function compute(){

var opt = document.getElementById("currency").value;

var inp = document.getElementById("value").value;

var amount = 0;

switch(opt){

case "usd - inr":

amount = (inp*62.04).toFixed(2);
break;

case "inr - usd":

amount = (inp/62.04).toFixed(2);

break;

case "eur - inr":

amount = (inp*71.01).toFixed(2);

break;

case "inr - eur":

amount = (inp/71.01).toFixed(2);

break;

document.getElementById("amount").value = amount;

</script>

</head>

<body>

<div id="header">

<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">

<span>

<img align="left" src="logo.jpeg" width="120px" height="120px">

</span>

</td>

<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>


</center>

</span>

</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>

<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-left:30px">Log in</a>

</span>

</td>

</tr>

</table>

</div>

<!-- Fill code here -->

<div align= "center">

<h2> Multiple Currency Converter </h2>

<label for="currency">Select the Conversion Type</label>

<select id ="currency">

<option value="usd - inr">USD - INR</option>

<option value="inr - usd">INR - USD</option>

<option value="eur - inr">EUR - INR</option>

<option value="inr - eur">INR - EUR</option>

</select>

<br><br>

<label for="value">Enter the Value</label>

<input id ="value"/>

<input type = "button" id="convert" onclick= compute() value= "Convert"/>

<br><br>

<label for="amount">Equivalent amount</label>


<input type = "number" id ="amount"/>

</div>

</body>

</html>

Looping Controls - CC

Asset Maintenance Log: -

<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

</style>

</head>

<div id="header">

<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">

<span>

<img align="left" src="logo.jpeg" width="120px"


height="120px">

</span>

</td>
<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>

</center>

</span>

</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>

<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-


left:30px">Log in</a>

</span>

</td>

</tr>

</table>

</div>

<script>

function compute(){

var desc = (document.getElementById("asset_log").value).trim();

var res = desc.split(",");

var total=0;

for(i=0; i<res.length;i+=3){

total = total+(res[((i+3)-1)]*1);

document.getElementById("result").innerHTML = "Your total amount is "+total;

}
</script>

</head>

<body onload="reLoad()">

<div>

<h2 align= "center">Asset Maintenance Log</h2>

<p align = "center">

Enter Asset Log:

<textarea id="asset_log" cols="40" rows="5" >

</textarea>

</p>

<p align = "center">

<input type = "button" id="submit" value="Submit" onclick = "compute()"/>

</p>

</div>

<div id ="result" align = "center">

</div>

</body>

</html>

Functions - CC

Number of days: -

Script.js: -

function calculate()

var a = new Date(document.getElementById("start").value);

var b = new Date(document.getElementById("end").value);


var c = 0;

var cd = a;

while (cd<=b)

var dow = cd.getDay();

if(!((dow==6)||(dow===0)))

c++;

cd.setDate(cd.getDate()+1)

var msg =c;

document.getElementById("result").innerHTML = "Number of working days is : "+msg;

Index.html:-

<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

</style>

<script src="script.js"></script>

</head>

<body>
<div id="header">

<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">

<span>

<img align="left" src="logo.jpeg" width="120px" height="120px">

</span>

</td>

<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>

</center>

</span>

</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>

<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-left:30px">Log in</a>

</span>

</td>

</tr>

</table>

</div>

<h2>Number of days</h2>

<table>

<tr>

<td>Start date (mm/dd/yyyy)</td>

<td><input type="text" id ="start"></td>


</tr>

<tr>

<td>End date (mm/dd/yyyy)</td>

<td><input type="text" id="end"></td>

</tr>

<tr>

<td><button type="submit" id="calculate" onclick="calculate()">Calculate</button></td>

</tr>

</table>

<div id="result"></div>

</body>

</html>

Working with Arrays - CC

Frequency Calculation: -

Index.html: -

<html>

<head>

<script type="text/javascript" src = "script.js">

</script>

</head>

<body>

<div align = "center">

<h2 align= "center">Frequecy Calculation</h2>

<p align = "center">

Enter the Address :

<textarea id="string" cols="40" rows="5" >

</textarea>
</p>

<input type ="button" id="check" value="Check Frequency" onclick =


"calculateFrequency()"/>

</div>

<div id ="result" align = "center">

</div>

</body>

</html>

Script.js: -

function calculateFrequency()

var text = document.getElementById('string').value.trim();

text= text.toLowerCase();

var newtxt = text.replace(/ /g, "");

var arr = [...newtxt];

arr.sort();

var obj = new Array();

for(var i=0;i<arr.length;i++)

var counter =0;

for(var j=0;j<arr.length;j++)

if(arr[i]== arr[j])

counter = counter+1;

}
}

obj[arr[i]] = counter;

temp = "";

for(var i in obj)

temp = temp+(i + " - " + obj[i] + '<br>');

document.getElementById('result').innerHTML = temp;

Objects and Methods - CC

Compute the Purchase Cost: -

Script.js: -

function getItemDetails() {

// fill code here

var items = createItem();

var i = 0;

var y = "<h2 align='center'>Compute the Purchase Cost</h2><div align='center'>The Item Details


are</div><table id='myTable' align='center'>";

y = y + "<tr><th>Select</th><th>Item Name</th><th>Price</th><th>Available Quantity</th><th>Enter


the quantity</th></tr>";

for(item in items){

y = y + "<tr>";
y = y + "<td><input type='checkbox' id='check"+ i +"'></td>";

y = y + "<td>" + items[item].itemName + "</td>";

y = y + "<td>"+ items[item].price + "</td>";

y = y + "<td>"+ items[item].availableQuantity + "</td>";

y = y + "<td><input type='text' id='text"+ i + "' oninput='compute()'></td>";

y = y + "</tr>";

i = i+1;

y = y + "</table>";

document.getElementById("test").innerHTML = y;

function compute(){

// fill code here

var cost = 0;

var items = createItem();

var comp = document.getElementById("text0").value;

if(document.getElementById("check0").checked === true){

if(comp !== null || comp.trim() !==""){

cost = cost + ((parseInt(comp))* items[0].price);

//cost = cost + ((parseInt(comp))* 35000);

}
var lap = document.getElementById("text1").value;

if(document.getElementById("check1").checked === true){

if(lap !== null || lap.trim() !==""){

cost = cost + ((parseInt(lap))* items[1].price);

var mob = document.getElementById("text2").value;

if(document.getElementById("check2").checked === true){

if(mob !== null || mob.trim() !==""){

cost = cost + ((parseInt(mob))* items[2].price);

var tel = document.getElementById("text3").value;

if(document.getElementById("check3").checked === true){

if(tel !== null || tel.trim() !==""){

cost = cost + ((parseInt(tel))* items[3].price);

var ref = document.getElementById("text4").value;

if(document.getElementById("check4").checked === true){

if(ref !== null || ref.trim() !==""){

cost = cost + ((parseInt(ref))* items[4].price);

document.getElementById("result").innerHTML = "The total purchased cost is " + cost;


}

function Item(itemName,price,availableQuantity)

this.itemName = itemName;

this.price = price;

this.availableQuantity = availableQuantity;

function createItem()

var itemArray=new Array();

var element;

element=new Item("Computer","35000",5);

itemArray.push(element);

element=new Item("Laptop","45000",9);

itemArray.push(element);

element=new Item("Mobile","15000",15);

itemArray.push(element);

element=new Item("Television","25000",8);

itemArray.push(element);

element=new Item("Refrigerator","30000",6);

itemArray.push(element);

return itemArray;

}
Index.html: -

<html>

<style>

table, th, td {

border: 1px solid black;

</style>

<head>

<script src="script.js" type="text/javascript"> </script>

</head>

<body onload="getItemDetails()">

<!--Fill code here-->

<div id="test" align="center"></div>

<div id="result" align="center"></div>

</body>

</html>

User Details

function bindValues()
{

var name = document.getElementById("name").value;

var address = document.getElementById("address").value;

var mobileNumber = document.getElementById("mobile").value;

var email = document.getElementById("email").value;

var user = new User(name,address,mobileNumber,email);

//fill code here

function validate()

var name = document.getElementById("name").value;

var mobileNumber = document.getElementById("mobile").value;

var email = document.getElementById("email").value;

var address = document.getElementById("address").value;

var nameWarning = document.getElementById("nameWarning");

var mobileWarning = document.getElementById("mobileWarning");

var emailWarning = document.getElementById("emailWarning");

var flagEmail = 0;

var flagName = 0;

var flagMobile = 0;

var emailMatch = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

if(name==="" || name===" ")

nameWarning.innerHTML = "Please Enter the name";

else {

nameWarning.innerHTML = "";

flagName = 1;

}
if(email==="" || email===" ")

emailWarning.innerHTML = "Please enter the E-mail";

else if(emailMatch.test(email) === false)

emailWarning.innerHTML = "Invalid Email";

else {

emailWarning.innerHTML = "";

flagEmail = 1;

if(mobileNumber==="" || mobileNumber===" ")

mobileWarning.innerHTML = "Please Enter the mobile number";

else if(mobileNumber.length !==10)

mobileWarning.innerHTML = "Invalid MobileNumber";

else {

mobileWarning.innerHTML = "";

flagMobile = 1;

if (flagName==1 && flagEmail==1 && flagMobile ==1){

var result = document.getElementById("result");

result.innerHTML = "Name :"+name+"<br>"+"Address :"+address+"<br>"+"Mobile Number


:"+mobileNumber+"<br>"+"Email :"+email;

function User(name,address,mobileNumber,email) {

this.name = name;

this.address = address;

this.mobileNumber = mobileNumber;

this.email = email;
}

<html>

<head>

<script src="script.js" type="text/javascript"> </script>

</head>

<body>

<div id="body" align="center">

<h2>User Details</h2>

<table>

<tr>

<td>Name*</td>

<td><input type="text" id="name" /></td>

<td><div id="nameWarning" style="color:red"></div></td>

</tr>

<tr>

<td>Address</td>

<td><textarea id="address"></textarea></td>

<td></td>

</tr>

<tr>

<td>Mobile Number*</td>

<td><input type="text" id="mobile" /></td>

<td><div id="mobileWarning" style="color:red"></div></td>

</tr>
<tr>

<td>E-mail Id*</td>

<td><input type="text" id="email" /></td>

<td><div id="emailWarning" style="color:red"></div></td>

</tr>

<tr>

<td></td>

<td><button id="submit" onclick="return validate();">Submit</button></td>

<td></td>

</tr>

</table>

</div>

<div id="result" align="center"></div>

<!--fill code here-->

</body>

</html>

DOM Events and Event Listeners - CC

Shipment Details Insertion: -

Index.html: -

<html>

<head>

<style>

td{

padding-bottom: .5em;

padding-top: .5em;
}

#table1{

padding-left: 300px;

padding-right: 100px;

#resultTable{

</style>

<script src="script.js" type="text/javascript"> </script>

</head>

<body>

<table id="table1" align="left"><br/>

<h2 align="center">Shipment Details Insertion</h2><br/><br/>

<tr>

<td>Name</td>

<td> <input type="text" id ="name" name="name"></td>

</tr>

<tr>

<td>ShipmentId</td>

<td> <input type = "text" id ="id" name="id" ></td>


</tr>

<tr>

<td>Source</td>

<td> <input type="text" id ="source" name="source"></td>

</tr>

<tr><td>Destination</td>

<td><input type="text" id ="destination" name="destination"></td></tr>

<tr><td>Position</td>

<td><input type="text" id ="position" name="position"></td></tr>

<tr>

<td colspan="2" align="center"><button type="button" id="insert" name="insert"


onclick="insert()">Insert</button>

</td>

</tr>

<tr>

<td colspan='2'>

<div id="result" align="left"></div>

</td>

</tr>

</table>

<table id="resultTable" border="1">

<tr>

<th>Name</th><th>ShipmentId</th><th>Source</th><th>Destination</th></tr>

<tr>
<td>Edward</td>

<td>56789543</td>

<td>Delhi</td>

<td>America</td>

</tr>

<tr>

<td>Aster</td>

<td>56789234</td>

<td>Norway</td>

<td>India</td>

</tr>

<tr>

<td>Charle</td>

<td>98789234</td>

<td>Japan</td>

<td>China</td>

</tr>

<tr>

<td>Vikrant</td>

<td>98695234</td>

<td>Australia</td>

<td>North America</td>

</tr>

</table>

</body>

</html>
Script.js: -

function insert()

var table = document.getElementById("resultTable");

var rname=document.getElementById("name").value;

var rsid=document.getElementById("id").value;

var rsource=document.getElementById("source").value;

var rdest=document.getElementById("destination").value;

var rpos=document.getElementById("position").value;

var row = table.insertRow(rpos);

var cell1 = row.insertCell(0);

var cell2 = row.insertCell(1);

var cell3 = row.insertCell(2);

var cell4 = row.insertCell(3);

cell1.innerHTML = rname;

cell2.innerHTML = rsid;

cell3.innerHTML = rsource;

cell4.innerHTML = rdest;

document.getElementById("name").value="";

document.getElementById("id").value="";

document.getElementById("source").value="";

document.getElementById("destination").value="";

document.getElementById("position").value="";

}
AJAX - CC

Display asset details using AJAX

Index.html: -

<html>

<head>

<style>

</style>

<script src="script.js" type="text/javascript"> </script>

</head>

<body>

<center>

<form>

<h2>Asset Details</h2>

<label>Enter ID to Search : </label><input type="text" id="input" onkeyup="search()"/>

<div id="result">

</div>

</center>

</body>

</html>

Script.js:-

function search(){

var id = document.getElementById("input").value;

var idArr=[];

var nameArr=[];

var desArr=[];
var filteredContactArr=[];

var xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

var myobj = JSON.parse(this.responseText);

var contactArr = myobj.contactList;

var len = contactArr.length;

for(var i=0;i<len;i++)

idArr[idArr.length]=contactArr[i].id;

nameArr[nameArr.length]=contactArr[i].name;

desArr[desArr.length]=contactArr[i].des;

for(var i=0;i<idArr.length;i++)

var str = idArr[i].split("");

if(id==str[0]||id==(str[0]+str[1])||id==(str[0]+str[1]+str[2]))

filteredContactArr[filteredContactArr.length]=idArr[i];

filteredContactArr[filteredContactArr.length]=nameArr[i];

filteredContactArr[filteredContactArr.length]=desArr[i];

if(filteredContactArr.length==0)

var txt1 = "No Result Found";

document.getElementById("result").innerHTML=txt1;

//document.getElementById("result").style.display="block";

}
else

var txt ="<table border='1'><tr><th>Asset ID</th><th>Asset


Name</th><th>Description</th></tr>";

for(var b=0;b<filteredContactArr.length;)

txt =
txt+"<tr><td>"+filteredContactArr[b]+"</td><td>"+filteredContactArr[b+1]+"</td><td>"+filteredContact
Arr[b+2]+"</td></tr>";

b=b+3;

txt=txt+"</table>";

document.getElementById("result").innerHTML=txt;

};

xmlhttp.open("GET", "asset.json", true);

xmlhttp.send();

************************************************************************************
HTML - Print Welcome Message
<!DOCTYPE html>

<html>

<body>

<p>WELCOME TO DATAX SHIPPING COMPANY</p>

</body>

</html>

Simple Website Using HTML tags


<!DOCTYPE html>

<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

td{
padding-top: .5em;

padding-bottom: .5em;

</style>

</head>

<body>

<div id="header">

<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">

<span>

<img align="left" src="logo.jpeg" width="120px" height="120px">

</span>
</td>

<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>

<h2>Welcome to DATAX Shipping Company</h2>

<h3>About us :</h3>

<p>

</p>

</center>

</span>

</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>
<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-left:30px">Log in</a>

</span>

</td>

</tr>

</table>

</div>

<table id="table1" align="center">

<center><h2>Asset Id ending with 5</h2></center>

<tr><td>Enter the Asset id</td>

<td> <textarea id="asset" name="asset" rows="5" cols="20"></textarea></td>

</tr>

<tr>
<td colspan="2" align="center" > <button type="button" id="compute" name ="compute"
onclick=compute()>Compute</button></td>

</tr>

<tr>

<td colspan="2">

<div id="result" align ="center"></div></td>

</tr>

</table>

<script>

function compute()

var val=document.getElementById("asset").value;

//alert(val);
var value1="";

var array=new Array();

array=val.split(",");

for(var a=0; a< array.length;a++)

if((array[a]%10)==5)

value1=value1+array[a]+",";

value1 = value1.replace(/,\s*$/, "");

document.getElementById("result").innerHTML=" Asset id ending with 5 are "+value1;


}

</script>

</body>

</html>

Shipping Charge Calculation


<!DOCTYPE html>

<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

text-align: center;

</style>

</head>

<body>

<div id="header">
<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">

<span>

<img align="left" src="logo.jpeg" width="120px" height="120px">

</span>

</td>

<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>

</center>

</span>

</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>

<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-left:30px">Log in</a>

</span>

</td>

</tr>

</table>

<h3>Calculation of Shipping charge</h3>

Total product weight : <input type="text" id="weight"><br>

Shiping Cost (per kg): <input type="text" id="cost"><br>

<button type="button" id="compute" align="center" onclick='multiply();'>Compute</button>

<script>
function multiply()

var fival= parseInt(document.getElementById('weight').value);

var Secval=parseInt(document.getElementById('cost').value);

var result= fival * Secval;

var value = document.getElementById("result").innerHTML ='The Total Shipment charge is


'+result;

</script>

<div id="result" lable=value>

</body>

</html>

Average cost of the Shipment


<!DOCTYPE html>
<html>

<head>
<style>
#header {
border: 1px solid lightgrey;

margin : -8px -8px 0;


background-color: lightgrey;
}
</style>
</head>

<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg" width="120px" height="120px">
</span>

</td>
<td style="width: 60%;">
<span>
<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>
</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">


<span>
<a href="#" id="signup">Sign up</a>
<a href="#" id="login" style="padding-left:30px">Log in</a>

</span>
</td>
</tr>
</table>

<h3>Average Shipment cost Calulation</h3>


Shiping Iteam cost <input type="text" id="itemCost"><br>
<button type="button" id="calculate" align="center"
onclick='average();'>Calculate</button><br>
Average shipment cost <input type="text" id="result"><br>
<script>
function average()
{
var number=document.getElementById('itemCost').value;
var outer_item=number.split(",");

var total = 0;
for(var i = 0; i < outer_item.length; i++) {
total += Number(outer_item[i]);

var avg = total / outer_item.length;


var value = document.getElementById("result").value =avg;

}
</script>

</body>

</html>
Control Flow - LC

1.Cargo Shipping Cost Calculation


<!DOCTYPE html>
<html>
<head>

<style>
#header {
border: 1px solid lightgrey;
margin : -8px -8px 0;

background-color: lightgrey;
}
</style>
<script>

function compute(){
var weight = document.getElementById('weight').value;
var cost = 0;
if(document.getElementById('air').checked){

cost = 1*weight;
}
else if (document.getElementById('road').checked){
cost = 0.5*weight;

}
else{
cost=0.7*weight;
}
if(document.getElementById('premium').checked){
cost = cost -((cost*12)/100)
}
document.getElementById('result').innerHTML = "Dear Customer, your total
shipping cost is $"+cost;
}
</script>
</head>

<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg" width="120px" height="120px">

</span>
</td>
<td style="width: 60%;">
<span>
<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>

</td>
<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">
<span>
<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-left:30px">Log in</a>


</span>
</td>
</tr>

</table>
</div>
<!-- fill code here -->
<h3 align= "center">Cargo Shipping Cost Calculation</h3>
<p align = "center">
weight(in kg):
<input type = "text" id="weight"/>
</p>
<p align = "center">
Transport Mode :
<input type = "radio" name= "mode" id="air"/>
<input type = "radio" name= "mode" id="road"/>
<input type = "radio" name= "mode" id="ship"/>
</p>
<p align = "center">

Premium Customer:
<input type = "checkbox" id="premium"/>
</p>
<p align = "center">
<input type = "button" id="calculate" onclick= compute() value= "Calculate"/>
</p>
<div id ="result" align = "center">
</div>

</body>

</html>

2. Password Validation

<!DOCTYPE html>
<html>

<head>
<style>
#header {
border: 1px solid lightgrey;
margin : -8px -8px 0;
background-color: lightgrey;
}
</style>

<script type="text/javascript">
function compute(){
var pass = document.getElementById('password').value;
var repass = document.getElementById('repassword').value;
if (pass==repass){
var res = "Registration is Successful<br><br>"+"<h2> Welcome to DATAX
Shipping Company</h2>"
document.getElementById('message').innerHTML = res;
document.getElementById('message').style="color:green";
}
else{
document.getElementById('errorMessage').innerHTML = "Registration failed
<br> Password and re-enter password doesn't match";
}
}
</script>
</head>

<body>
<div id="header">

<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg" width="120px" height="120px">
</span>
</td>
<td style="width: 60%;">
<span>
<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>
</td>
<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">
<span>
<a href="#" id="signup">Sign up</a>
<a href="#" id="login" style="padding-left:30px">Log in</a>
</span>

</td>
</tr>
</table>

</div>
<!-- fill code here -->
<form>
<div align= "center" id ="message">

<h3> Registration Form </h3>


<div id="errorMessage" style="color:red;"></div>
<label for="username">Username:<label/>
<input type = "text" id ="username"/>

<br><br>
<label for="password">Password:<label/>
<input type = "password" id ="password"/>
<br><br>

<label for="repassword">Re-enter Password:<label/>


<input type = "password" id ="repassword"/>
<br><br>
<label for="mobile">Mobile Number:<label/>
<input type = "number" id ="mobile"/>
<br><br>
<input type = "button" id="register" onclick= compute() value= "Register"/>
</div>

</form>
</body>

</html>

Looping Controls - LC

1.Number Sequence
<!DOCTYPE html>
<html>
<head>
<style>
#header {
border: 1px solid lightgrey;

margin : -8px -8px 0;


background-color: lightgrey;
}
</style>
</head>

<body>
<script type="text/javascript">
function findNum()
{
var addr = document.getElementById("address").value;
var reg = /\d+/g

var res = addr.match(reg);

//document.getElementById("result").innerHTML = "num length " + nums.length;


document.getElementById("result").innerHTML = "The sequence of numbers are " + res;
}
</script>

<div id="header">
<table style="width:100%">

<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg" width="120px" height="120px">
</span>
</td>
<td style="width: 60%;">
<span>

<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>

</td>
<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">
<span>
<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-left:30px">Log in</a>


</span>
</td>
</tr>
</table>
<!-- fill code here -->
<center>
<h2>Shipping Details</h2>
<table>
<tr>
<td>Enter the Address:</td>
<td><textarea id='address' rows=5 cols=32></textarea></td>
</tr>
</table>
<br><br>

<input type='button' id='calculate' Value = 'Calculate' onclick='findNum()'>


<br><br>
<div id='result'></div>
</center>
</body>

</html>

2.Customer Help Desk


<html>
<head>
<style>
#header {
border: 1px solid lightgrey;
margin : -8px -8px 0;

background-color: lightgrey;
}
</style>
</head>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg"
width="120px" height="120px">
</span>
</td>
<td style="width: 60%;">

<span>
<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>
</td>
<td style="width: 40%; padding-bottom: 7%;padding-
left:5%;">
<span>
<a href="#" id="signup">Sign up</a>
<a href="#" id="login" style="padding-
left:30px">Log in</a>
</span>
</td>
</tr>
</table>
</div>

<h2 style="text-align: center">Customer Help Desk</h2>


<table cellpadding="2" width="20%" align="center" cellspacing="10">
<tr>
<td>Description</td>
<td><textarea id="description"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="button" id="submit" onClick="details()" Value="Submit" /></td>
</tr>
</table>
<div id="success" style="visibility:hidden; margin-left:150px; color:#00ff00" /><b> Hi Thanks for
your message<b> <br>
We will get back to you shortly

</div>

<div id="warning" />Your message should not exceed more than 100 words </div>

<script>

function details()
{

var num = document.getElementById("description").value;


var len= num.match(/\S+/g).length;
if(len>100)
{
document.getElementById("warning").style.visibility = "visible";
}
else

document.getElementById("success").style.visibility = "visible";

}
</script>

</head>
<!-- Your code here -->

</body>
</html>

Functions – LC

1. Checking Number

<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

</style>

<script type="text/javascript">

function check() {

//'use strict';

var inputValue = document.getElementById("input").value;

//console.log(isNaN(inputValue));

//if(typeof inputValue ==='number')

if (isNaN(inputValue)) {

document.getElementById("result").style.color = 'red';

document.getElementById("result").innerHTML = "The Given input is not a number";

}else

document.getElementById("result").style.color = 'green'
document.getElementById("result").innerHTML = "The Given input is a number";

</script>

</head>

<body>

<div id="header">

<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">

<span>

<img align="left" src="logo.jpeg" width="120px" height="120px">

</span>

</td>

<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>

</center>

</span>

</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>

<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-left:30px">Log in</a>

</span>

</td>

</tr>
</table>

</div>

<h2>Checking Number</h2>

Enter the input <textarea id="input"></textarea>

<input type="button" id="check" value="Check" onclick="check()" />

<div id="result"></div>

</body>

</html>

2. Date Validation

<!DOCTYPE html>

<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

#textArea{

width: 200px;

height: 150px;

</style>

<div id="header">

<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">
<span>

<img align="left" src="logo.jpeg" width="120px"


height="120px">

</span>

</td>

<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>

</center>

</span>

</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>

<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-


left:30px">Log in</a>

</span>

</td>

</tr>

</table>

</div>

<script type="text/javascript" src ="script.js"></script>

</head>

<body>

<div align = "center">

<h2 align= "center">Date Validation</h2>


<p align = "center">

Enter Date (dd-MM-yyyy):

<input type= "text" id="date"/>

</p>

<input type ="button" id="calculate" value="Calculate" onclick = "dateValidate()"/>

</div>

<div id ="result" align = "center">

</div>

</body>

script.js

function dateValidate()

var input = document.getElementById('date').value;

var bits = input.split('-');

var d = new Date(bits[2], bits[1] - 1, bits[0]);

if(d.getFullYear() == bits[2] && (d.getMonth() + 1) == bits[1] && d.getDate() == Number(bits[0]))

document.getElementById('result').innerHTML = "Date is valid";

document.getElementById('result').style = "color:green"

else

document.getElementById('result').innerHTML = "Date is invalid";

document.getElementById('result').style = "color:red"

3.Mobile Number Validation


<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

</style>

<script type="text/javascript">

function validate()

var inp = document.getElementById('mobileNumber').value;

var letters = /^\(?[(]?([0-9]{3})\)?[)]?([0-9]{3})[-]?([0-9]{4})$/;

if(inp.match(letters))

document.getElementById('result').innerHTML = "Mobile Number is valid";

document.getElementById('result').style = "color:green"

else

document.getElementById('result').innerHTML = "Mobile Number is invalid";

document.getElementById('result').style = "color:red"

</script>

</head>

<body>
<div id="header">

<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">

<span>

<img align="left" src="logo.jpeg" width="120px" height="120px">

</span>

</td>

<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>

</center>

</span>

</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>

<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-left:30px">Log in</a>

</span>

</td>

</tr>

</table>

</div>

<div align = "center">

<h2 align= "center">Mobile Number Validation</h2>

<p align = "center">

Enter the Mobile Number

<input type= "text" id="mobileNumber"/>


</p>

<input type ="button" id="validate" value="Validate" onclick =


"validate()"/>

</div>

<div id ="result" align = "center">

</div>

</body>

</html>

5.Vowels Count

<html>

<head>

<style>

#header {

border: 1px solid lightgrey;

margin : -8px -8px 0;

background-color: lightgrey;

</style>

<div id="header">

<table style="width:100%">

<tr style="width:100%">

<td style="width:20%">

<span>

<img align="left" src="logo.jpeg" width="120px"


height="120px">

</span>
</td>

<td style="width: 60%;">

<span>

<center>

<h1>DATAX Shipping Company</h1>

</center>

</span>

</td>

<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">

<span>

<a href="#" id="signup">Sign up</a>

<a href="#" id="login" style="padding-


left:30px">Log in</a>

</span>

</td>

</tr>

</table>

</div>

<script type="text/javascript" src="script.js"></script>

</head>

<body>

Number of vowels

Enter the string: <input id="string" type="text" />

<input type="button" id="getVowel" value="Get vowels" onclick="getVowels()" />

<div id="result"></div>

</body>

</html>
scrtipt.js

function getVowels()

var inputString=document.getElementById("string").value;

var vowelC=0;

// var total_findVowles="";

for(var i=0;i<inputString.length;i++)

if (inputString.charAt(i).match(/[a-zA-Z]/)!=null)

if (inputString.charAt(i).match(/[aeiouAEIOU]/))

{ vowelC++;}

document.getElementById("result").innerHTML="Number of vowels : " + vowelC;

Working with Arrays - LC

1.Policy Details
<html>

<head>

<script src="script.js" type="text/javascript"> </script>


</head>

<body>

<div align = "center">

<h2 align= "center">Policy Details</h2>

<p align = "center">

Enter the Claim Number

<input type= "text" id="claimNumber"/>

</p>

<input type ="button" id="add" value="Add Claim" onclick =


"addPolicy()"/>

<input type ="button" id="display" value="Display Policy" onclick =


"displayPolicy()"/>

</div>

<div id ="result" align = "center">

</div>

</body>

</html>

Script.js

policy = new Array();

function addPolicy()

var len =policy.length;

var num = document.getElementById('claimNumber').value;

policy[len]=num.substring(0,4)

function displayPolicy()

document.getElementById('result').innerHTML ="The Policy numbers are "+policy;


policy=[];

2.Address Details

<html>

<head>

<script src="script.js" type="text/javascript"> </script>

</head>

<body>

<center>

Enter the Address : <textarea id="address" rows="3" cols="30"></textarea><br> <br>

<button type="button" id="add" onclick="addAddress()">Add Address</button><br><br>

<button type="button" id="display" onclick="displayAddress()">Display Address</button>

<br><br>

</center>

<div id="result"> </div>

</body>

</html>

script.js

var address = [];


function addAddress(){

var addr = document.getElementById("address");

if(addr.value.replace(/^\s+|\s+$/gm,'') !=="") {

address.push(addr.value);

addr.value = "";

function displayAddress(){

var display = [];

var addrno = [];

var result = document.getElementById("result");

result.innerHTML = "<h2>Address Details</h2>";

for(var i=0; i<address.length; i++){

display[i] = address[i];

addrno[i] = "Address "+(i+1);

result.innerHTML += addrno[i]+"<br>"+display[i]+"<br>";

display = [];

addrno = [];

address = [];

Objects and Methods - LC

1.Customer Details

<html>

<head>
<script src="script.js" type="text/javascript"> </script>

</head>

<body>

<div align = "center">

<h2 align= "center">Customer Details</h2>

<p align = "center">

Customer Name

<input type= "text" id="name"/><br><br>

Address

<textarea id="address" cols="40" rows="5" >

</textarea><br><br>

Phone Number

<input type= "text" id="number"/>

</p>

<input type ="button" id="display" value="Display" onclick =


"display()"/>

</div>

<div id ="result" align = "center">

</div>

</body>

</html>

script.js

function display(){

var name = document.getElementById('name').value.trim();

var adres = document.getElementById('address').value.trim();

var num = document.getElementById('number').value.trim();

var cus = new Customer(name,adres,num);

document.getElementById('result').innerHTML = cus.getInfo();
}

function Customer(name,adres,num)

this.name = name;

this.adres= adres;

this.num= num;

Customer.prototype.getInfo= function(){

temp = "Name :"+this.name+ '<br>'+"Address :"+this.adres+ '<br>'+"Phone


Number :"+this.num+ '<br>';

return temp;

};

3.Asset Summary

<html>

<head>

<script src = "script.js"></script>

<style>

table, th,td {

border: 1px solid black;

ul{

width:5%

}
li{

width:20%;

display:block;

li{

list-style:none;

clear:both;

li label{

float:left;

li span{

float:center;

li input{

float:right;

</style>

</head>

<body>

<center>

<h2>Asset Details</h2>

<ui>

<li>

<label>Asset ID</label>
<span>:</span>

<input id="asset_id" type="text"></input>

<br/>

<br/>

</li>

<li>

<label>Asset Type</label>

<span>:</span>

<input id="type" type="textbox"></input>

<br/>

<br/>

</li>

<li>

<label>Supplier Name</label>

<span>:</span>

<input id="supplier" type="textbox"></input>

<br/>

<br/>

</li>

<li>

<label>Manufacturer</label>

<span>:</span>

<input id="manufacturer" type="textbox"></input>

<br/>

<br/>

</li>

<li>

<button id="add" type="button" onclick="addAsset()">Add Asset</button>

<button id="display" type="button" onclick="displayAsset()">Display Asset</button>


</li>

<div id="result">

<h3></h3>

<table id="tab">

</table>

</div>

</ui>

</center>

</body>

script.js

var i=0;

var assetArray=[];

var assetquantity={};

function addAsset() {

var assetId = document.getElementById('asset_id').value;

var type = document.getElementById('type').value;

var supplier = document.getElementById('supplier').value;

var manufacturer = document.getElementById('manufacturer').value;

assetArray[i]=new Asset(assetId,type,supplier,manufacturer);

i++;

var elements = document.getElementsByTagName("input");

for (var ii=0; ii < elements.length; ii++) {

console.log(elements[ii].type);

if (elements[ii].type == "text") {
elements[ii].value = "";

function displayAsset() {

for(var j=0;j<assetArray.length;j++){

if(assetquantity[assetArray[j].type]){

assetquantity[assetArray[j].type]++;

} else{

assetquantity[assetArray[j].type]=1;

var k=1;

var result = document.getElementById('tab');

while (result.hasChildNodes()) {

result.removeChild(result.lastChild);

document.getElementById('result').getElementsByTagName('h3')[0].innerHTML="Asset Details";

var ir = result.insertRow(0);

ir.insertCell(0).outerHTML="<th>Asset Type</th>"

ir.insertCell(1).outerHTML="<th>Quantity</th>"

for(var assetname in assetquantity){

var row = result.insertRow(k);

var cell1 = row.insertCell(0);

var cell2 = row.insertCell(1);


cell1.innerHTML=assetname;

cell2.innerHTML=assetquantity[assetname];

k++;

i=0;

assetArray=[];

assetquantity={};

function Asset(assetId,type,supplier,manufacturer){

this.assetId=assetId;

this.type=type;

this.supplier=supplier;

this.manufacturer=manufacturer;

Object Oriented Programming - LC

1.User Details
<html>

<head>

<script src="script.js" type="text/javascript"> </script>

</head>

<body>

<div id="body" align="center">

<h2>User Details</h2>
<table>

<tr>

<td>Name*</td>

<td><input type="text" id="name" /></td>

<td><div id="nameWarning" style="color:red"></div></td>

</tr>

<tr>

<td>Address</td>

<td><textarea id="address"></textarea></td>

<td></td>

</tr>

<tr>

<td>Mobile Number*</td>

<td><input type="text" id="mobile" /></td>

<td><div id="mobileWarning" style="color:red"></div></td>

</tr>

<tr>

<td>E-mail Id*</td>

<td><input type="text" id="email" /></td>

<td><div id="emailWarning" style="color:red"></div></td>

</tr>

<tr>

<td></td>

<td><button id="submit" onclick="return validate();">Submit</button></td>

<td></td>

</tr>

</table>

</div>

<div id="result" align="center"></div>


<!--fill code here-->

</body>

</html>

script.js

function bindValues()

var name = document.getElementById("name").value;

var address = document.getElementById("address").value;

var mobileNumber = document.getElementById("mobile").value;

var email = document.getElementById("email").value;

var user = new User(name,address,mobileNumber,email);

//fill code here

function validate()

var name = document.getElementById("name").value;

var mobileNumber = document.getElementById("mobile").value;

var email = document.getElementById("email").value;

var address = document.getElementById("address").value;

var nameWarning = document.getElementById("nameWarning");

var mobileWarning = document.getElementById("mobileWarning");


var emailWarning = document.getElementById("emailWarning");

var flagEmail = 0;

var flagName = 0;

var flagMobile = 0;

var emailMatch = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

if(name==="" || name===" ")

nameWarning.innerHTML = "Please Enter the name";

else {

nameWarning.innerHTML = "";

flagName = 1;

if(email==="" || email===" ")

emailWarning.innerHTML = "Please enter the E-mail";

else if(emailMatch.test(email) === false)

emailWarning.innerHTML = "Invalid Email";

else {

emailWarning.innerHTML = "";

flagEmail = 1;

if(mobileNumber==="" || mobileNumber===" ")

mobileWarning.innerHTML = "Please Enter the mobile number";

else if(mobileNumber.length !==10)

mobileWarning.innerHTML = "Invalid MobileNumber";

else {

mobileWarning.innerHTML = "";

flagMobile = 1;

if (flagName==1 && flagEmail==1 && flagMobile ==1){

var result = document.getElementById("result");


result.innerHTML = "Name :"+name+"<br>"+"Address :"+address+"<br>"+"Mobile Number
:"+mobileNumber+"<br>"+"Email :"+email;

function User(name,address,mobileNumber,email) {

this.name = name;

this.address = address;

this.mobileNumber = mobileNumber;

this.email = email;

DOM Events and Event Listeners - LC

2.Shipment Entry Form


<html>

<head>

<style>

#Shipment{

background-color: #e6e6e6;

padding-top: 15px;

padding-left: 150px;

padding-right: 150px;

border-style: solid;

td{

padding-bottom: .5em;

padding-top: .5em;
}

h2{

text-align: center;

div{

color: red;

#result{

color:green;

#submit{

display: block;

margin: auto;

</style>

<script src="script.js" type="text/javascript"> </script>

</head>

<body onload="generateShippingDate()">

<table id ="Shipment" align="center">

<tr><td colspan="3"><h2>Start Shipping</h2></td></tr>

<tr><td colspan="3"><hr></td></tr>

<tr><td colspan="3"><div id="result"></div></td></tr>

<tr><td colspan="2"> From </td></tr>

<tr> <td colspan="2">Country</td>

<td><select id="country" onchange="fieldValidate()">

<option value="select">Select the country</option>

<option value="India">India</option>

<option value="Bahrain">Bahrain</option>
<option value="Albania">Albania</option>

<option value="Algeria">Algeria</option>

<option value="Algeria">America</option>

<option value="Andorra">Andorra</option>

<option value="Burundi">Burundi</option>

<option value="Cambodia">Cambodia</option>

<option value="Greece">Greece</option>

<option value="Greenland">Greenland</option>

<option value="Canada">Canada</option>

<option value="Afghanistan">Afghanistan</option>

</select></td>

<td><div id="errorCountry"></div></td>

</tr>

<tr> <td colspan="2">Languages</td>

<td><select id="language" onchange="fieldValidate()">

<option value="select">Select the language</option>

<option value="Tamil">Tamil</option>

<option value="English">English</option>

<option value="Spanish">Spanish</option>

<option value="Greek">Greek</option>

<option value="French">French</option>

<option value="Russian">Russian</option>

<option value="Hindi">Hindi</option>

<option value="Arabic">Arabic</option>

<option value="German">German</option>

<option value="Spanish">Spanish</option>

<option value="Farsi">Farsi</option>

</select></td>

<td><div id="errorLanguage"></div></td> </tr>


<tr> <td colspan="2"> Postal code</td>

<td><input type="text" id="postalCode" name="postalCode" onchange="fieldValidate()"></td>

<td><div id="errorPostal"></div></td> </tr>

<tr> <td colspan="2"> City</td>

<td><input type="text" id="city" name="city" onchange="fieldValidate()"></td>

<td><div id="errorCity"></div></td> </tr>

<tr> <td colspan="2">Suburb</td>

<td><input type="text" id="suburb" name="suburb" onchange="fieldValidate()"></td>

<td><div id="errorSuburb"></div></td>

</tr>

<tr><td colspan="2">Mobile Number</td>

<td><input type="text" id="mobile" name="mobile" onchange="fieldValidate()"></td>

<td><div id="errorMobile"></div></td>

</tr>

<tr><td colspan="3"><hr></td></tr>

<tr><td colspan="2"> To </td></tr>

<tr> <td colspan="2"> Country</td>

<td><select id="toCountry" onchange="fieldValidate()">

<option value="select">Select the country</option>

<option value="India">India</option>

<option value="Bahrain">Bahrain</option>

<option value="Albania">Albania</option>

<option value="Algeria">Algeria</option>

<option value="America">America</option>

<option value="Andorra">Andorra</option>

<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>

<option value="Greece">Greece</option>

<option value="Greenland">Greenland</option>

<option value="Canada">Canada</option>

<option value="Afghanistan">Afghanistan</option>

</select></td>

<td><div id="errortoCountry"></div></td>

</tr>

<tr> <td colspan="2">Languages</td>

<td><select id="toLanguage" onchange="fieldValidate()">

<option value="select">Select the language</option>

<option value="Tamil">Tamil</option>

<option value="English">English</option>

<option value="Spanish">Spanish</option>

<option value="Greek,">Greek,</option>

<option value="French">French</option>

<option value="Russian">Russian</option>

<option value="Hindi">Hindi</option>

<option value="Arabic">Arabic</option>

<option value="German">German</option>

<option value="Spanish">Spanish,</option>

<option value="Farsi">Farsi</option>

</select></td>

<td><div id="errortoLanguage"></div></td> </tr>

<tr> <td colspan="2"> Postal code</td>

<td><input type="text" id="toPostalCode" name="toPostalCode"


onchange="fieldValidate()"></td>

<td><div id="errortoPostal"></div></td> </tr>

<tr> <td colspan="2"> City</td>


<td><input type="text" id="toCity" name="toCity" onchange="fieldValidate()"></td>

<td><div id="errortoCity"></div></td> </tr>

<tr> <td colspan="2">Suburb</td>

<td><input type="text" id="toSuburb" name="toSuburb" onchange="fieldValidate()"></td>

<td><div id="errortoSuburb"></div></td> </tr>

<tr><td colspan="2">Mobile Number</td>

<td><input type="text" id="toMobile" name="toMobile" onchange="fieldValidate()"></td>

<td><div id="errortoMobile"></div></td>

</tr>

<tr><td colspan="3"><hr></td></tr>

<tr><td colspan="2">When do you need to ship?</td>

<td><select id="shipping" onchange="fieldValidate()" >

<option value="select">Select the Shipping Date</option>

<option value="select">Today</option></select></td><td> <div


id="errorShip"></div></td></tr>

<tr><td colspan="3"><button type="button" id="submit" name="submit"


onclick="registerShipping()" >Submit</button></td></tr>

</table>

</body>

</html>

script.js

function generateShippingDate() {

//Your code here

var date = new Date();

var day = date.getDate();


var month = date.getMonth();

var year = date.getFullYear();

var monArray;

var leap = false;

if (year % 4 === 0) {

if (year % 100 === 0) {

if (year % 400 === 0) {

leap = true;

else {

leap = false;

else {

leap = true;

else {

leap = false;

if (leap === true) {

monArray = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

else {

monArray = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

var dateArray = [];

if (day <= 25) {

var mon = month + parseInt(1);


while (day !== (monArray[month] + 1)) {

var dt = day + '/' + mon + '/' + year;

dateArray[dateArray.length] = dt;

day = day + 1;

else {

var mon = month + parseInt(1);

while (day !== (monArray[month] + 1)) {

var dt = day + '/' + mon + '/' + year;

dateArray[dateArray.length] = dt;

day = day + 1;

month = month + parseInt(1);

if (month === 12) {

month = 0;

year = year + 1;

mon = month + parseInt(1);

day = 1;

while (day !== (monArray[month] + 1)) {

var dt = day + '/' + mon + '/' + year;

dateArray[dateArray.length] = dt;

day = day + 1;

var len = dateArray.length;

var shipselect = document.getElementById("shipping");

shipselect.remove(1);
var option = document.createElement("option");

option.text = "Today";

option.value = "Today";

shipselect.add(option);

for (var i = 1; i < len; i++) {

var option = document.createElement("option");

option.text = dateArray[i];

option.value = dateArray[i];

shipselect.add(option);

var validArray = [false, false, false, false, false, false, false, false, false, false, false, false, false];

function fieldValidate() {

//Your code here

var country = document.getElementById("country").value;

if (country === "select") {

validArray[0] = false;

document.getElementById("errorCountry").innerHTML = 'Please select the country';

else {

validArray[0] = true;

document.getElementById("errorCountry").innerHTML = '';

var language = document.getElementById("language").value;

if (language === "select") {

validArray[1] = false;

document.getElementById("errorLanguage").innerHTML = 'Please select the language';

else {
validArray[1] = true;

document.getElementById("errorLanguage").innerHTML = '';

var postalCode = document.getElementById("postalCode").value;

if (postalCode === "" || postalCode === " " || postalCode === null) {

validArray[2] = false;

document.getElementById("errorPostal").innerHTML = 'Please enter the postal code';

else {

validArray[2] = true;

document.getElementById("errorPostal").innerHTML = '';

var city = document.getElementById("city").value;

if (city === "" || city === " " || city === null) {

validArray[3] = false;

document.getElementById("errorCity").innerHTML = 'Please enter the city';

else {

validArray[3] = true;

document.getElementById("errorCity").innerHTML = '';

var suburb = document.getElementById("suburb").value;

if (suburb === "" || suburb === " " || suburb === null) {

validArray[4] = false;

document.getElementById("errorSuburb").innerHTML = 'Please enter the suburb';

else {

validArray[4] = true;

document.getElementById("errorSuburb").innerHTML = '';
}

var mobile = document.getElementById("mobile").value;

if (mobile === "" || mobile === " " || mobile === null) {

validArray[5] = false;

document.getElementById("errorMobile").innerHTML = 'Please enter the mobile number';

else {

validArray[5] = true;

document.getElementById("errorMobile").innerHTML = '';

var toCountry = document.getElementById("toCountry").value;

if (toCountry === "select") {

validArray[6] = false;

document.getElementById("errortoCountry").innerHTML = 'Please select the country';

else {

validArray[6] = true;

document.getElementById("errortoCountry").innerHTML = '';

var toLanguage = document.getElementById("toLanguage").value;

if (toLanguage === "select") {

validArray[7] = false;

document.getElementById("errortoLanguage").innerHTML = 'Please select the language';

else {

validArray[7] = true;

document.getElementById("errortoLanguage").innerHTML = '';

var toPostalCode = document.getElementById("toPostalCode").value;


if (toPostalCode === "" || toPostalCode === " " || toPostalCode === null) {

validArray[8] = false;

document.getElementById("errortoPostal").innerHTML = 'Please enter the postal code';

else {

validArray[8] = true;

document.getElementById("errortoPostal").innerHTML = '';

var toCity = document.getElementById("toCity").value;

if (toCity === "" || toCity === " " || toCity === null) {

validArray[9] = true;

document.getElementById("errortoCity").innerHTML = 'Please enter the city';

else {

validArray[9] = true;

document.getElementById("errortoCity").innerHTML = '';

var toSuburb = document.getElementById("toSuburb").value;

if (toSuburb === "" || toSuburb === " " || toSuburb === null) {

validArray[10] = false;

document.getElementById("errortoSuburb").innerHTML = 'Please enter the suburb';

else {

validArray[10] = true;

document.getElementById("errortoSuburb").innerHTML = '';

var toMobile = document.getElementById("toMobile").value;

if (toMobile === "" || toMobile === " " || toMobile === null) {

validArray[11] = false;
document.getElementById("errortoMobile").innerHTML = 'Please enter the mobile number';

else {

validArray[11] = true;

document.getElementById("errortoMobile").innerHTML = '';

var shipping = document.getElementById("shipping").value;

//alert(shipping);

if (shipping === "select") {

validArray[12] = false;

document.getElementById("errorShip").innerHTML = 'Please select the shipping date';

else {

validArray[12] = true;

document.getElementById("errorShip").innerHTML = '';

function registerShipping() {

//Your code here

fieldValidate();

var result = false;

for (var i = 0; i < 13; i++) {

result = validArray[i];

if (result === false) {

break;

if (result === true) {


var shippingdate = document.getElementById("shipping").value;

if (shippingdate === "Today") {

var date = new Date();

var day = date.getDate();

var month = date.getMonth() + 1;

var year = date.getFullYear();

shippingdate = day + '/' + month + '/' + year;

document.getElementById("result").innerHTML = '<h2>Shipment Registered<br>Pick up is


scheduled on ' + shippingdate + '</h2>';

else {

document.getElementById("result").innerHTML = "";

3.Pickup Form Validation

<html>

<head>

<style>

#xx {

width: 700px;

height: 690px;

.button {

background-color: red;

border: none;

margin-top: 210px;

color: white;
padding: 10px 20px;

span {

color: red;

#hour, option {

width: 45px;

#minute, option {

width: 45px;

#ampm, option {

width: 55px;

#hour1, option {

width: 45px;

#minute1, option {

width: 45px;

#ampm1, option {

width: 55px;
}

#contactError, #companyError, #address1Error, #cityError, #pieceError, #weightError,

#locationTypeError, #locationError {

color: red;

#zipError, #phoneError {

color: red;

.button button3 {

color: black;

</style>

<script src="script.js" type="text/javascript"></script>

</head>

<body onload="preloadDetails()">

<center>

<h2>Schedule a Pickup</h2>

<div style="border-style: solid; background-color:lightgrey" id="xx">

<table style="float:left; margin-left:10px;">

<tr>

<td>Schedule Pickup</td>

</tr>

<tr>

<td>Pickup</td>

</tr>

<tr>
<td>Contact<span>*</span></td>

<td></td>

</tr>

<tr>

<td><input type="text" id="contact" onchange="fieldValidate()"></td>

<td><div id="contactError"></div></td>

</tr>

<tr>

<td>Company<span>*</span></td>

<td></td>

</tr>

<tr>

<td><input type="text" id="company" onchange="fieldValidate()"></td>

<td><div id="companyError"></div></td>

</tr>

<tr>

<td>Address 1<span>*</span></td>

<td></td>

</tr>

<tr>

<td><input type="text" id="address1" onchange="fieldValidate()"></td>

<td><div id="address1Error"></div></td>

</tr>

<tr>

<td>Address 2</td>

<td></td>

</tr>

<tr>

<td><input type="text" id="address2"></td>


</tr>

<tr>

<td>Address 3</td>

<td></td>

</tr>

<tr>

<td><input type="text" id="address3"></td>

</tr>

<tr>

<td>City<span>*</span></td>

<td></td>

</tr>

<tr>

<td><input type="text" id="city" onchange="fieldValidate()"></td>

<td><div id="cityError"></div></td>

</tr>

<tr>

<td>State/Province</td>

<td></td>

</tr>

<tr>

<td><input type="text" id="state"></td>

<td></td>

</tr>

<tr>

<td>Zip/Postal Code<span>*</span></td>

<td></td>

</tr>

<tr>
<td><input type="text" id="zipcode" onchange="fieldValidate()"></td>

<td><div id="zipError"></div></td>

</tr>

<tr>

<td>Country</td>

</tr>

<tr>

<td><input type="text" id="country"></td>

<td></td>

</tr>

<tr>

<td>Phone<span>*</span></td>

<td></td>

</tr>

<tr>

<td><input type="text" id="phone" onchange="fieldValidate()"></td>

<td><div id="phoneError"></div></td>

</tr>

<tr>

<td>Total pieces in shipment(s)<span>*</span></td>

<td></td>

</tr>

<tr>

<td><input type="text" id="piece" size="4" onchange="fieldValidate()"></td>

<td><div id="pieceError"></div></td>

</tr>

<tr>

<td>Total weight of shipent(s)<span>*</span></td>

<td></td>
</tr>

<tr>

<td><input type="text" id="weight" size="8" onchange="fieldValidate()"></td>

<td><div id="weightError"></div></td>

</tr>

</table>

<div style="margin-top:47px"></div>

<table style="float:left background-color:lightgrey">

<tr>

<td>Location Type<span>*</span></td>

</tr>

<tr>

<td>

<select style="width:100px" id="locationType" onchange="fieldValidate()">

<option value="Select">Select</option>

<option value="Business">Business</option>

<option value="Personal">Personal</option>

<option value="Economic">Economic</option>

</select>

</td>

<td><div id="locationTypeError"></div></td>

</tr>

<tr>

<td>Location of shipment(s)<span>*</span></td>

<td></td>

</tr>

<tr>

<td><input type="text" id="location" onchange="fieldValidate()"></td>

<td><div id="locationError"></div></td>
</tr>

<tr>

<td>Special Instructions</td>

</tr>

<tr>

<td><textarea id="instruction"></textarea></td>

</tr>

<tr>

<td>Pickup Date</td>

</tr>

<tr>

<td>

<select style="width:150px" id="date">

<option value=1>TODAY</option>

<option value=2>TOMORROW</option>

</select>

</td>

</tr>

<tr>

<td>My Shipment will be ready by</td>

</tr>

<tr>

<td>

<select name="hour" id="hour" onchange="fieldValidate()"></select>

<select name="minute" id="minute" onchange="fieldValidate()"></select>

<select name="format" id="format" onchange="fieldValidate()"></select>

</td>

</tr>

<tr>
<td>Your pickup must be ready by</td>

<td><div id="pickupready"></div></td>

</tr>

<tr>

<td>Office closes at</td>

</tr>

<tr>

<td>

<select name="hour1" id="hour1" disabled>

<option value="06">06</option>

</select>

<select name="minute1" id="minute1" disabled>

<option value="30">30</option>

</select>

<select name="format1" id="format1" disabled>

<option value="PM">PM</option>

</select>

</td>

</tr>

</table>

<div style="margin-top:100px" id="result"></div>

<button style="margin-top:50px; color:black" id="validate" class="button button3"


onclick="submitSchedule()">Schedule Pickup</button>

</div>

</center>

</body>

</html>
script.js

function preloadDetails() {

//fill code here

var hour = document.getElementById("hour");

for (var i = 1; i <= 12; i++) {

var option = document.createElement("option");

if (i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7 || i == 8 || i == 9) {

option.text = '0' + i;

option.value = '0' + i;

else {

option.text = i;

option.value = i;

hour.add(option);

var minute = document.getElementById("minute");

for (var i = 0; i <= 59; i++) {

var option = document.createElement("option");

if (i == 0 || i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7 || i == 8 || i == 9) {

option.text = '0' + i;

option.value = '0' + i;

else {

option.text = i;

option.value = i;

minute.add(option);
}

var format = document.getElementById("format");

var option = document.createElement("option");

option.text = "AM";

option.value = "AM";

format.add(option);

option = document.createElement("option");

option.text = "PM";

option.value = "PM";

format.add(option);

function fieldValidate() {

//fill code here

var hasError = false;

var contact = document.getElementById("contact").value;

if (contact == "" || contact == " " || contact == null) {

document.getElementById("contactError").innerHTML = "Please enter the field";

hasError = true;

} else {

document.getElementById("contactError").innerHTML = "";

var company = document.getElementById("company").value;

if (company == "" || company == " " || company == null) {

document.getElementById("companyError").innerHTML = "Please enter the field";

hasError = true;

} else {
document.getElementById("companyError").innerHTML = "";

var address1 = document.getElementById("address1").value;

if (address1 == "" || address1 == " " || address1 == null) {

document.getElementById("address1Error").innerHTML = "Please enter the field";

hasError = true;

} else {

document.getElementById("address1Error").innerHTML = "";

var city = document.getElementById("city").value;

if (city == "" || city == " " || city == null) {

document.getElementById("cityError").innerHTML = "Please enter the field";

hasError = true;

} else {

document.getElementById("cityError").innerHTML = "";

var zipcode = document.getElementById("zipcode").value;

if (zipcode == "" || zipcode == " " || zipcode == null) {

document.getElementById("zipError").innerHTML = "Please enter the field";

hasError = true;

} else {

document.getElementById("zipError").innerHTML = "";

var phone = document.getElementById("phone").value;

if (phone == "" || phone == " " || phone == null) {

document.getElementById("phoneError").innerHTML = "Please enter the field";

hasError = true;

} else {

document.getElementById("phoneError").innerHTML = "";
}

var piece = document.getElementById("piece").value;

if (piece == "" || piece == " " || piece == null) {

document.getElementById("pieceError").innerHTML = "Please enter the field";

hasError = true;

} else {

document.getElementById("pieceError").innerHTML = "";

var weight = document.getElementById("weight").value;

if (weight == "" || weight == " " || weight == null) {

document.getElementById("weightError").innerHTML = "Please enter the field";

hasError = true;

} else {

document.getElementById("weightError").innerHTML = "";

var locationType = document.getElementById("locationType").value;

if (locationType == "Select") {

document.getElementById("locationTypeError").innerHTML = "Please enter the field";

hasError = true;

} else {

document.getElementById("locationTypeError").innerHTML = "";

var location = document.getElementById("location").value;

if (location == "" || location == " " || location == null) {

document.getElementById("locationError").innerHTML = "Please enter the field";

hasError = true;

} else {

document.getElementById("locationError").innerHTML = "";

}
var hour = document.getElementById("hour").value;

var minute = document.getElementById("minute").value;

var format = document.getElementById("format").value;

if (format == "PM") {

hour = parseInt(hour) + 12;

if (hour == 24) {

hour = '12';

else if (format == "AM") {

if (hour == 12) {

hour = '00';

var timeString = hour + ':' + minute;

document.getElementById("pickupready").innerHTML = timeString;

return hasError;

function submitSchedule() {

//fill code here

if (!fieldValidate()) {

document.getElementById("result").innerHTML = "<b>Your Shipment pickup is scheduled at " +


document.getElementById("hour").value + ":" + document.getElementById("minute").value +
document.getElementById("format").value;

document.getElementById("contact").value = "";

document.getElementById("company").value = "";

document.getElementById("address1").value = "";
document.getElementById("address2").value = "";

document.getElementById("address3").value = "";

document.getElementById("city").value = "";

document.getElementById("state").value = "";

document.getElementById("zipcode").value = "";

document.getElementById("country").value = "";

document.getElementById("phone").value = "";

document.getElementById("piece").value = "";

document.getElementById("weight").value = "";

document.getElementById("locationType").value = "Select";

document.getElementById("location").value = "";

document.getElementById("instruction").value = "";

document.getElementById("date").value = "1";

document.getElementById("hour").value = "01";

document.getElementById("minute").value = "00";

document.getElementById("format").value = "AM";

AJAX - LC

1.Displaying Shipment Details Using JSON Data


<html>

<head>

<style>

#result table

border-collapse: collapse;
position: relative;

#result td, #result th

border: 1px solid black;

</style>

<script type="text/javascript" src="script.js"></script>

<!--script src="data.json"></script-->

</head>

<body onload="loadDoc()">

<!--fill your code here-->

<center>

<h2>Shipment Details</h2>

<div id='result'>

<table id ='myTable'>

<tr>

<th>Shipment Number</th>

<th>Source</th>

<th>Destination</th>

<th>Start Date</th>

<th>Delivered Date</th>

<th>Weight</th>

</tr>

</table>

</div>

</center>

</body>

</html>
script.js

function loadDoc(){

var table = document.getElementById("myTable");

var xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

var myobj = JSON.parse(this.responseText);

var bookArr = myobj.book;

var len = bookArr.length;

var tableLength = table.rows.length;

for(var i=0;i<len;i++)

var row = table.insertRow(tableLength);

var cell1 = row.insertCell(0);

var cell2 = row.insertCell(1);

var cell3 = row.insertCell(2);

var cell4 = row.insertCell(3);

var cell5 = row.insertCell(4);

var cell6 = row.insertCell(5);

cell1.innerHTML = bookArr[i].Booking_ID;

cell2.innerHTML = bookArr[i].Arrival_Port;

cell3.innerHTML = bookArr[i].Departure_Port;

cell4.innerHTML = bookArr[i].Arrival_Date;

cell5.innerHTML = bookArr[i].Departure_Date;

cell6.innerHTML = bookArr[i].Weight;

tableLength=tableLength+1;

};
xmlhttp.open("GET", "data.json", true);

xmlhttp.send();

data.json

"book": [

"Booking_ID" : "12789651",

"Arrival_Port" : "Chennai",

"Departure_Port" : "Coimbatore",

"Arrival_Date" : "2017-07-07 12:00",

"Departure_Date" : "2017-07-09 23:00",

"Weight" : "1500 Kgs"

},

"Booking_ID" : "98781121",

"Arrival_Port" : "Mumbai",

"Departure_Port" : "Delhi",

"Arrival_Date" : "2018-05-11 10:00",

"Departure_Date" : "2018-05-21 12:30",

"Weight" : "1000 Kgs"

},

"Booking_ID" : "17896500",

"Arrival_Port" : "Coimbatore",

"Departure_Port" : "Salem",

"Arrival_Date" : "2017-12-11 06:00",


"Departure_Date" : "2017-12-11 10:00",

"Weight" : "100 Kgs"

},

"Booking_ID" : "34290111",

"Arrival_Port" : "Bangalore",

"Departure_Port" : "Cochin",

"Arrival_Date" : "2018-05-07 23:00",

"Departure_Date" : "2018-05-12 10:00",

"Weight" : "900 Kgs"

2.Search Customer Details in XML Using Ajax


<!DOCTYPE html>

<html>

<head>

<style>
</style>

<script src="script.js" type="text/javascript"> </script>

</head>

<body>

<!--Your Code here-->

<center>

<h2>Shipment Details</h2>

<div id='test'>

<table cellpadding="25">

<tr align="center">

<td><br><br>Enter the Customer Name <input type="text"


id="name"/><br><br><br>

<input type="button" id="search" onClick="search()" Value="Search"/><br><br></td>

</tr>

</div>

<br>

<br>

</table>

<div id='result'>

</div>

</center>

</body>

</html>

script.js
function search(){

var xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

myFunction(this);

};

xmlhttp.open("GET", "ShipmentDetails.xml", true);

xmlhttp.send();

function myFunction(xml) {

var cName = document.getElementById("name").value;

var resArray = [];

var a, alen, x, y, i, j, xlen, xmlDoc, txt;

xmlDoc = xml.responseXML;

a = xmlDoc.getElementsByTagName("name");

alen = a.length;

for(j=0;j<alen;j++)

if(a[j].childNodes[0].nodeValue==cName)

x = xmlDoc.getElementsByTagName("shipment")[j];

xlen = x.childNodes.length;

y = x.firstChild;

for (i = 0; i < xlen; i++)

if (y.nodeType == 1)

{
resArray[resArray.length] = y.childNodes[0].nodeValue;

y = y.nextSibling;

if(resArray.length===0)

var txt1 = '<h2>No Result Found</h2>';

document.getElementById("result").innerHTML=txt1;

else

var txt ='<table id ="resultTable"


border="1"><thead><tr><th>ShipmentId</th><th>Name</th><th>Source</th><th>Destination</th><th
>Start Date</th><th>Delivered Date</th></tr></thead>';

for(var b=0;b<resArray.length;)

txt =
txt+'<tr><td>'+resArray[b+1]+'</td><td>'+resArray[b]+'</td><td>'+resArray[b+2]+'</td><td>'+resArray[
b+3]+'</td><td>'+resArray[b+4]+'</td><td>'+resArray[b+5]+'</td></tr>';

b=b+6;

txt=txt+'</table>';

document.getElementById("result").innerHTML=txt;

}
ShipmentDetails.xml

<?xml version="1.0" encoding="UTF-8"?>

<catalog>

<shipment>

<name>Charles</name>

<shipmentId>46789056</shipmentId>

<source>India</source>

<destination>North America</destination>

<startDate>05/06/2017</startDate>

<deliveredDate>26/06/2017</deliveredDate>

</shipment>

<shipment>

<name>Charles</name>

<shipmentId>46789696</shipmentId>

<source>Delhi</source>

<destination>Greece</destination>

<startDate>09/06/2017</startDate>

<deliveredDate>30/06/2017</deliveredDate>

</shipment>

<shipment>

<name>Edward</name>

<shipmentId>98767894</shipmentId>

<source>Pune</source>

<destination>Italy</destination>

<startDate>25/06/2017</startDate>
<deliveredDate>05/07/2017</deliveredDate>

</shipment>

<shipment>

<name>Aster</name>

<shipmentId>88950075</shipmentId>

<source>Italy</source>

<destination>California</destination>

<startDate>25/08/2017</startDate>

<deliveredDate>06/09/2017</deliveredDate>

</shipment>

<shipment>

<name>Aster</name>

<shipmentId>88950075</shipmentId>

<source>Japan</source>

<destination>China</destination>

<startDate>25/07/2017</startDate>

<deliveredDate>29/07/2017</deliveredDate>

</shipment>

<shipment>

<name>Vikrant</name>

<shipmentId>98765240</shipmentId>

<source>New york</source>

<destination>Chennai</destination>

<startDate>03/07/2017</startDate>

<deliveredDate>10/07/2017</deliveredDate>

</shipment>
</catalog>
JavaScript Multiple Choice Questions and Answers- Sheet 1
1. Why so JavaScript and Java have similar name?
A. JavaScript is a stripped-down version of Java
B. JavaScript's syntax is loosely based on Java's
C. They both originated on the island of Java
D. None of the above
Ans: B

2. When a user views a page containing a JavaScript program, which machine actually executes the
script?
A. The User's machine running a Web browser
B. The Web server
C. A central machine deep within Netscape's corporate offices
D. None of the above
Ans: A

3. ______ JavaScript is also called client-side JavaScript.


A. Microsoft
B. Navigator
C. LiveWire
D. Native
Ans: B

4. __________ JavaScript is also called server-side JavaScript.


A. Microsoft
B. Navigator
C. LiveWire
D. Native
Ans: C

5. What are variables used for in JavaScript Programs?


A. Storing numbers, dates, or other values
B. Varying randomly
C. Causing high-school algebra flashbacks
D. None of the above
Ans: A

6. _____ JavaScript statements embedded in an HTML page can respond to user events such as mouse-
clicks, form input, and page navigation.
A. Client-side
B. Server-side
C. Local
D. Native
Ans: A

7. What should appear at the very end of your JavaScript?


The <script LANGUAGE="JavaScript">tag
A. The </script>
B. The <script>
C. The END statement
D. None of the above
Ans: A

8. Which of the following can't be done with client-side JavaScript?


A. Validating a form
B. Sending a form's contents by email
C. Storing the form's contents to a database file on the server
D. None of the above
Ans: C

9. Which of the following are capabilities of functions in JavaScript?


A. Return a value
B. Accept parameters and Return a value
C. Accept parameters
D. None of the above
Ans: C

10. Which of the following is not a valid JavaScript variable name?


A. 2names
B. _first_and_last_names
C. FirstAndLast
D. None of the above
Ans: A

11. ______ tag is an extension to HTML that can enclose any number of JavaScript statements.
A. <SCRIPT>
B. <BODY>
C. <HEAD>
D. <TITLE>
Ans: A

12. How does JavaScript store dates in a date object?


A. The number of milliseconds since January 1st, 1970
B. The number of days since January 1st, 1900
C. The number of seconds since Netscape's public stock offering.
D. None of the above
Ans: A

13. Which of the following attribute can hold the JavaScript version?
A. LANGUAGE
B. SCRIPT
C. VERSION
D. None of the above
Ans: A

14. What is the correct JavaScript syntax to write "Hello World"?


A. System.out.println("Hello World")
B. println ("Hello World")
C. document.write("Hello World")
D. response.write("Hello World")
Ans: C
15. Which of the following way can be used to indicate the LANGUAGE attribute?
A. <LANGUAGE="JavaScriptVersion">
B. <SCRIPT LANGUAGE="JavaScriptVersion">
C. <SCRIPT LANGUAGE="JavaScriptVersion"> JavaScript statements…</SCRIPT>
D. <SCRIPT LANGUAGE="JavaScriptVersion"!> JavaScript statements…</SCRIPT>
Ans: C

16. Inside which HTML element do we put the JavaScript?


A. <js>
B. <scripting>
C. <script>
D. <javascript>
Ans: C

17. What is the correct syntax for referring to an external script called " abc.js"?
A. <script href=" abc.js">
B. <script name=" abc.js">
C. <script src=" abc.js">
D. None of the above
Ans: C

18. Which types of image maps can be used with JavaScript?


A. Server-side image maps
B. Client-side image maps
C. Server-side image maps and Client-side image maps
D. None of the above
Ans: B

19. Which of the following navigator object properties is the same in both Netscape and IE?
A. navigator.appCodeName
B. navigator.appName
C. navigator.appVersion
D. None of the above
Ans: A

20. Which is the correct way to write a JavaScript array?


A. var txt = new Array(1:"tim",2:"kim",3:"jim")
B. var txt = new Array:1=("tim")2=("kim")3=("jim")
C. var txt = new Array("tim","kim","jim")
D. var txt = new Array="tim","kim","jim"
Ans: C

21. What does the <noscript> tag do?


A. Enclose text to be displayed by non-JavaScript browsers.
B. Prevents scripts on the page from executing.
C. Describes certain low-budget movies.
D. None of the above
Ans: A

22. If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the
paragraph?
A. "New Text"?
B. para1.value="New Text";
C. para1.firstChild.nodeValue= "New Text";
D. para1.nodeValue="New Text";
Ans: B

23. JavaScript entities start with _______ and end with _________.
A. Semicolon, colon
B. Semicolon, Ampersand
C. Ampersand, colon
D. Ampersand, semicolon
Ans: D

24. Which of the following best describes JavaScript?


A. a low-level programming language.
B. a scripting language precompiled in the browser.
C. a compiled scripting language.
D. an object-oriented scripting language.
Ans: D

25. Choose the server-side JavaScript object?


A. FileUpLoad
B. Function
C. File
D. Date
Ans: C

26. Choose the client-side JavaScript object?


A. Database
B. Cursor
C. Client
D. FileUpLoad
Ans: D

27. Which of the following is not considered a JavaScript operator?


A. new
B. this
C. delete
D. typeof
Ans: B

28. ______method evaluates a string of JavaScript code in the context of the specified object.
A. Eval
B. ParseInt
C. ParseFloat
D. Efloat
Ans: A

29. Which of the following event fires when the form element loses the focus: <button>, <input>,
<label>, <select>, <textarea>?
A. onfocus
B. onblur
C. onclick
D. ondblclick
Ans: B

30. The syntax of Eval is ________________


A. [objectName.]eval(numeriC.
B. [objectName.]eval(string)
C. [EvalName.]eval(string)
D. [EvalName.]eval(numeriC.
Ans: B

31. JavaScript is interpreted by _________


A. Client
B. Server
C. Object
D. None of the above
Ans: A

32. Using _______ statement is how you test for a specific condition.
A. Select
B. If
C. Switch
D. For
Ans: B

33. Which of the following is the structure of an if statement?


A. if (conditional expression is true) thenexecute this codeend if
B. if (conditional expression is true)execute this codeend if
C. if (conditional expression is true) {then execute this code>->}
D. if (conditional expression is true) then {execute this code}
Ans: C

34. How to create a Date object in JavaScript?


A. dateObjectName = new Date([parameters])
B. dateObjectName.new Date([parameters])
C. dateObjectName := new Date([parameters])
D. dateObjectName Date([parameters])
Ans: A

35. The _______ method of an Array object adds and/or removes elements from an array.
A. Reverse
B. Shift
C. Slice
D. Splice
Ans: D

36. To set up the window to capture all Click events, we use which of the following statement?
A. window.captureEvents(Event.CLICK);
B. window.handleEvents (Event.CLICK);
C. window.routeEvents(Event.CLICK );
D. window.raiseEvents(Event.CLICK );
Ans: A

37. Which tag(s) can handle mouse events in Netscape?


A. <IMG>
B. <A>
C. <BR>
D. None of the above
Ans: B

38. ____________ is the tainted property of a window object.


A. Pathname
B. Protocol
C. Defaultstatus
D. Host
Ans: C

39. To enable data tainting, the end user sets the _________ environment variable.
A. ENABLE_TAINT
B. MS_ENABLE_TAINT
C. NS_ENABLE_TAINT
D. ENABLE_TAINT_NS
Ans: C

40. In JavaScript, _________ is an object of the target language data type that encloses an object of
the source language.
A. a wrapper
B. a link
C. a cursor
D. a form
Ans: A

41. When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type
___________
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B

42. _______ class provides an interface for invoking JavaScript methods and examining JavaScript
properties.
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B

43. _________ is a wrapped Java array, accessed from within JavaScript code.
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: A

44. A ________ object is a reference to one of the classes in a Java package, such as
netscape.javascript .
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: B

45. The JavaScript exception is available to the Java code as an instance of __________
A. netscape.javascript.JSObject
B. netscape.javascript.JSException
C. netscape.plugin.JSException
D. None of the above
Ans: B

46. To automatically open the console when a JavaScript error occurs which of the following is added
to prefs.js?
A. user_pref(" javascript.console.open_on_error", false);
B. user_pref("javascript.console.open_error ", true);
C. user_pref("javascript.console.open_error ", false);
D. user_pref("javascript.console.open_on_error", true);
Ans: D

47. To open a dialog box each time an error occurs, which of the following is added to prefs.js?
A. user_pref("javascript.classic.error_alerts", true);
B. user_pref("javascript.classic.error_alerts ", false);
C. user_pref("javascript.console.open_on_error ", true);
D. user_pref("javascript.console.open_on_error ", false);
Ans: A

48. The syntax of a blur method in a button object is ______________


A. Blur()
B. Blur(contrast)
C. Blur(value)
D. Blur(depth)
Ans: A

49. The syntax of capture events method for document object is ______________
A. captureEvents()
B. captureEvents(args eventType)
C. captureEvents(eventType)
D. captureEvents(eventVal)
Ans: C

50. The syntax of close method for document object is ______________


A. Close(doC.
B. Close(object)
C. Close(val)
D. Close()
Ans: D

51. <script type="text/javascript">


x=4+"4";
document.write(x);
</script>

Output------?
A. 44
B. 8
C. 4
D. Error output
Ans: A

52. Is it possible to nest functions in JavaScript?


A. True
B. False
Ans: A

53. <script>
document.write(navigator.appCodeName);
</script>
A. get code name of the browser of a visitor
B. set code name of the browser of a visitor
C. None of the above
Ans: A

54. Scripting language are


A. High Level Programming language
B. Assembly Level programming language
C. Machine level programming language
Ans: A

55. Which best explains getSelection()?


A. Returns the VALUE of a selected OPTION.
B. Returns document.URL of the window in focus.
C. Returns the value of cursor-selected text
D. Returns the VALUE of a checked radio input.
Ans: C

56. Choose the client-side JavaScript object:


A. Database
B. Cursor
C. Client
D. FileUpLoad
Ans: D

57. What is mean by "this" keyword in javascript?


A. It refers current object
B. It referes previous object
C. It is variable which contains value
D. None of the above
Ans: A

58. In JavaScript, Window.prompt() method return true or false value ?


A. False
B. True
Ans: A

59. <script language="javascript">


function x()
{
document.write(2+5+"8");
}
</script>
A. 258
B. Error
C. 7
D. 78
Ans: D

60. <script type="text/javascript">


var s = "9123456 or 80000?";
var pattern = /\d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
A. 9123
B. 91234
C. 80000
D. None of the above
Ans: A
Javascript Quiz Questions and Answers-Sheet 2
1) <script type="text/javascript">
x=4+"4";
document.write(x);
</script>

Output------?
a) 44
b) 8
c) 4
d) Error output

2) <script type="text/javascript" language="javascript">


var qpt = "Qualiyt Point Technologies";
var result = qpt.split(" ");
document.write(result);
</script>
a) Quality
b) Q,u,a,l,i,t,y,P,o,i,n,t,T,e,c,h,n,o,l,o,g,i,e,s
c) Qualiyt,Point,Technologies
d) QualityPointTechnologies

3) Is it possible to nest functions in JavaScript?


a) True
b) False

4) <script>
document.write(navigator.appCodeName);
< /script>
a) get code name of the browser of a visitor
b) set code name of the browser of a visitor
c) None of the above

5) Which of the following is true?


a) If onKeyDown returns false, the key-press event is cancelled.
b) If onKeyPress returns false, the key-down event is cancelled.
c) If onKeyDown returns false, the key-up event is cancelled.
d) If onKeyPress returns false, the key-up event is canceled.

6) Scripting language are


a) High Level Programming language
b) Assembly Level programming language
c) Machine level programming language
Show Answer

7) Which best explains getSelection()?


a) Returns the VALUE of a selected OPTION.
b) Returns document.URL of the window in focus.
c) Returns the value of cursor-selected text
d) Returns the VALUE of a checked radio input.

8) <script language="javascript">
function x()
{
var s= "Good 100%";
var pattern = /\D/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error

9) <script language="javascript">
var qpt="QUALITY POINT TECHNOLOGIES";
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error

10) Choose the client-side JavaScript object:


a) Database
b) Cursor
c) Client
d) FileUpLoad

11) Are java and javascript the same?


a) NO
b) YES

12) Syntax for creating a RegExp object:


(a). var txt=new RegExp(pattern,attributes);
(b). var txt=/pattern/attributes;
Which of the above mentioned syntax will correct?
a) (a) only
b) (b) only
c) Both (a) and (b)
d) None of the above

13) <script language="javascript">


function x(z,t)
{
alert(x.length);
}
< /script>
output:
?
a) Error
b) 2
c) 1
d) 3

14) What is mean by "this" keyword in javascript?


a) It refers current object
b) It referes previous object
c) It is variable which contains value
d) None of the above

15) In JavaScript, Window.prompt() method return true or false value ?


a) False
b) True
c) None of above

16) Math. round(-20.51)=?


a) 20
b) -21
c) 19
d) None

17) <script language="javascript">


function x()
{
var s = "Quality 100%!{[!!";
var pattern = /\w/g;
var output = s.match(pattern);
document.write(output);
}
</script>
a) %,!,{,[,!,!
b) Q,u,a,l,i,t,y,1,0,0
c) Quality 100
d) Error

18) <script type="text/javascript" language="javascript">


var qpt= new Array();
qpt[0] = "WebDevelopment";
qpt[1]="ApplicationDevelopment"
qpt[2]="Testing"
qpt[3] = "QualityPointTechnologies";
document.write(qpt[0,1,2,3]);
</script>
a) Error
b) QualityPointTechnologies
c) WebDevelopment
d) WebDevelopmnet,ApplicationDevelopment,Testing,QualityPointTechnologies

19) Choose the server-side JavaScript object:


a) FileUpLoad
b) Function
c) File
d) Date

20) parseFloat(9+10)=?
a) 19
b) 910
c) None

21) <script language="javascript">


function x()
{
document.write(2+5+"8");
}
</script>
a) 258
b) Error
c) 7
d) 78

22)_________ keyword is used to declare variables in javascript.


a) Var
b) Dim
c) String
23) In Javascript, Which of the following method is used to evaluate the regular expression?
a) eval(2*(3+5))
b) evaluate(2*(3+5))
c) evalu(2*(3+5))
d) None of the above

24) <script language="javascript">


function x()
{
var s= "quality 100%";
var pattern = /\d/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) 100
b) 1,0,0
c) q,u,a,l,i,t,y,%
d) Error

25) <script type="text/javascript" language="javascript">

qpt=((45%2)==0)? "hello" : "bye";


document.write(qpt);

</script>
a) hello
b) bye
c) Error in string handling
d) None of the above

26)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern));
}
</script>
a) Error
b) POIiNT
c) Point
d) null
27) How do you create a new object in JavaScript?
a) var obj = {};
b) var obj = Object();
c) var obj=new {};
d) None of the above

28) In Javascript, What does isNaN function do ?


a) Return true if the argument is not a number.
b) Return false if the argument is not a number.
c) Return true if the argument is a number.
d) None of the above

29) If x=103 & y=9 then x%=y , what is the value of x after executing x%=y?
a) 4
b) 3
c) 2
d) 5

30) Choose the external object:


a) Date
b) Option
c) Layer
d) Checkbox

31) Choose the four symbol pairs that represent RegExp properties lastMatch, lastParent,
leftContext, and rightContext, respectively:
a) $&, $+, $`, $'
b) $+, $&, $', $`
c) $&, $~, $`, $'
d) $+, $&, $`, $'

32) Which of the following properties hold the values of the pixels of the length of the width
and height of the viewer's screen resolution?
a) screen.width and screen.height
b) Resolution.width and Resolution.height
c) screen.pixels.width and screen.pixels.height
d) ViewerScreen.width and ViewerScreen.height

33) ParseInt(“15”,10)=?
a) 15
b) 10
c) 151
d) 150

34) Which JavaScript feature uses JAR files?


a) Object signing
b) Style sheets
c) Netcaster channels
d) Image rollovers

35)How to assign a function to a variable with the JavaScript Function contructor ?


a) var f=Function("x","y","return x+y");
b) var f=Function(x,y){ return x+y;}
c) var f= new Function("x", "y", "return x + y");

36) In JavaScript, Window.alert() is used to allow user to enter something


a) True
b) False
c) None of above

37) <script language="javascript">


function x()
{
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","gi");

document.write(pattern.exec(qpt) + " ");


document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
}

</script>
a) in in In
b) in in in
c) in in null
d) in null null

38) Is Javascript has any date data type?


a) Yes
b) No

39) Math. round(-20.5)=?


a) -21
b) 20
c) -20
d) 21
40) ?_name is it valid javascript identifier?
a) Yes
b) No

41) <script language="javascript">


function x()
{
var qpt = "First come, first served";
var pattern = /first/gi;
document.write(qpt.match(pattern)[1]);
}
</script>

a) first
b) undefined
c) First
d) Error

42) (a). // , /* ...... **/


(b). / , /** ......./ , /*
(c). /*......*/ , //
(d). \*......*\ , //

In javascript, Which of the above Comments lines are used ?


a) Only (d)
b) Only (c)
c) Either (c) or (d)
d) Only (b)

43) <script language="javascript">


function x()
{
var s = "Give 100%!{[!!";
var pattern = /\W/g;
var output = s.match(pattern);
document.write(output);
}
</script>
a) ,%,!,{,[,!,!
b) G,i,v,e,1,0,0
c) Give 100
d) Error

44) Which best describes void?


a) A method
b) A function
c) A statement
d) An operator

45) <script type="text/javascript" language="javascript">


var qpt="QualityPointTechnologies";
var result =qpt.lastIndexOf("l");
document.write(result);
</script>
a) 3
b) 18
c) 17
d) 19

46) <script language="javascript">


function x()
{
var qpt = "First come, first served";
var pattern = /first/g;
document.write(qpt.match(pattern)[1]);
}
</script>
a) first
b) First
c) undefined
d) None of the above

47) <script language="javascript">


function sum(x)
{
function add(y)
{
return x+y;
}
return add;
}
function callme() { result=sum(5)(5); alert(result); }
</script>

If you call the function callme(), what will happen ?


a) 10
b) Error in calling Function
c) 5
d) None of the above

48) Who invented the javascript programming language?


a) Tennis Ritchie
b) James Gosling
c) Brendan Eich

49) <script type="text/javascript">


document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
</script>
Can you write HTML tag inside the javascript ?
a) No
b) Yes
c) Impossible

50) Which feature is supported in MSIE 3.x?


a) split()
b) document.clear()
c) join()
d) charAt()

51) How to speicfy the color of the hypertext links with JavaScript ?
a) document.linkColor="#00FF00";
b) document.LColor="#00FF00";
c) document.LinkC="#00FF00";
d) document.hyperTextLink="#00FF00":

52) <script language="javascript">


function x()
{
var qpt = "QualityPointTechnologies";
var pattern = /point/;

var output= qpt.search(pattern);

document.write("Position: " + output);


}
</script>
a) Position-7
b) Position-1
c) null
d) error

53) --------------- method returns the number of milliseconds in a date string.


a) setHours()
b) setMinutes()
c) parse()

54) ------------- converts a string to floating point numbers.


a) eval
b) ParseInt
c) ParseFloat
d) None

55) ---------------------- attempts to evaluate a string representing any javascript literals or


variables, converting it to a number.
a) eval
b) parseFloat
c) parseInt
d) None

56) Which is not an attribute of the cookie property?


a) path
b) host
c) secure
d) domain

57) How do substring() and substr() differ?


a) One is not a method of the String object.
b) substr() takes three arguments, substring() only two.
c) Only one accepts a desired string length as an argument.
d) Besides the spelling, nothing.

58) Which is not a reserved word?


a) interface
b) short
c) program
d) throws

59) In Javascript, Which of the following method is used to find out the character at a
position in a string?
a) charAt()
b) CharacterAt()
c) CharPos()
d) characAt()

60) <script type="text/javascript" language="javascript">


var qpt = "QualityPointTechnologies";
var result =qpt.substring(7,8);
document.write(result);

</script>
a) Po
b) yP
c) oi
d) P

61) How do you delete an element from an options array?


a) Set it to false.
b) Set it to null.
c) Set it to undefined.
d) Set it to -1

62) Is javaScript case sensitive ?


a) Yes
b) No

63) JavaScript RegExp Object has modifier 'i' to __________


a) Perform case-sensitive matching
b) Perform case-insensitive matching
c) Perform both case-sensitive&case-insensitive matching

64) What are the following looping structures are available in javascripts?
a) for,forecach
b) foreach,whileloop
c) do-while loop,foreach
d) for , while loop

65) Which of these is not a method of the Math object?


a) atan()
b) atan2()
c) eval()
d) acos()

66) <script type="text/javascript">


var s = "9123456 or 80000?";
var pattern = /\d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
a) 9123
b) 91234
c) 80000
d) None of the above

67) In javascript, RegExp Object Method test() is used to search a string and returns
_________
a) true or false
b) found value
c) index
d) None of the above

68) What property would you use to redirect a visitor to another page?
a) document.URL
b) window.location.href
c) .document.location.href
d) link.href

69) a.) var qpt="Quality Point Technologies";

b.) var qpt=new String("Quality Point Technologies");

Question:
In javascript, which of the above statement can used for string declaration ?

a) Either (a) or (b)


b) Only (a)
c) Neither (a) nor (b)
d) Only (b)

70) <script type="text/javascript" language="javascript">


var qpt = "QualityPointTechnologies";
var result =qpt.indexOf("Tech");
document.write(result);
</script>
a) 11
b) 12
c) 15
d) 13

71) <script language="javascript">


function x()
{
var s = "Eat to live, but do not live to eat";
var pattern = new RegExp("eat$");
document.write(pattern.exec(s));
}
</script>
a) Eat
b) eat
c) undefined
d) Eat eat

72) <script language="javascript">


function x()
{
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","g");

document.write(pattern.exec(qpt) + " ");


document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
}

</script>
a) in in In
b) in in in
c) in in null
d) in null null

73) -------------- method is used to remove focus from the specified object.
a) blur()
b) focus()
c) None

74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer

75)eval((20*4)=?
a) Nan
b) 204
c) 24
d) 80

76)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("TECHNOLOGIES","i");
document.write(qpt.match(pattern));
}
</script>
a) null
b) Technologies
c) TECHNOLOGIES
d) Error

77)Javascript is a ________ typed language.


a) tightly
b) loosely
1. When a JSP is executed, out of the following, what is most likely to be sent to the client? Select
one:
a. The compiled Servlet file
b. The source JSP file
c. HTML
d. The source Servlet file
2. Which of the following tag disables scriplets?
a. <is-scripting-invalid>
b. None of the listed options
c. <scripting-disabled>
d. <scripting-invalid>
3. Which of the following options represents the presentation logic to provide the data of the
model in the MVC design pattern?
a. Connector
b. Controller
c. Model
d. View
4. Choose the lifecycle methods in JSP?
a. destroy()
b. _jspService()
c. jspDestroy()
d. _jspPost()
e. jspInit()
5. In JSP request implicit object is of which type?
a. HttpRequest
b. ServletHttpRequest
c. HttpServletRequest
d. ServletRequest
6. Which of the following methods can be overridden?
a. jspDestroy()
b. jspInit()
c. None of the listed options
d. _jspService()
7. <%! int a=6; %>
<% int a=5; %>
<% int b=3; %>
Result is <%= a*b %>
What is the result of the above code segment?
a. Will display 18
b. Will display 15
c. Compilation error
d. Will display a blank page
8. Translation and Compilation of JSP happens during:
a. Undeployment
b. Deployment
c. Execution
d. None of the listed options
9. Which of the following have default value set to true?
a. session
b. isELIgnored
c. isErrorpage
d. None of the listed options
10. Which of the following directives are applicable only to tag files?
a. variable
b. taglib
c. tab
d. page
11. Which of the following are not valid JSP code fragments?
a. <%! Int c; %>
b. <%Date d = new Date(); out.println(d); %>
c. <%@ page import=”java.util.*” %>
d. <%= String val = request.getParameter(“hello”); out.println(val); %>
12. Choose the valid JSP Expressions?
a. <%= ! false %>
b. <%= Math.random() %>
c. <%= aBool; %>
d. <%= sBuff.setLength(12) ;%>
13. Consider the following statements:
Statement A: A tag library descriptors an XML document that contains information about a
library as a whole and about each tag contained in the library.
Statement B: TLDs are used by a Web container to validate the tags used by JSP page
development tools.
Which of the following is true about these statements?
a. Statement A is false and statement B is false
b. Statement A is true and statement B is false
c. Statement A is true and statement B is true
d. Statement A is false and statement B is true
14. What would be the return value of the doStartTag() method of the Tag Handler class which tells
the JSP engine to continue evaluating the body content and any child tags of the tag
a. EVAL_PAGE
b. SKIP_BODY
c. EVAL_BODY
d. EVAL_BODY_INCLUDE
15. TagSupport and BodyTagSupport classes are present in which package?
a. javax.servlet.jsp.tag.ext
b. javax.servlet.jsp.tag
c. java.servlet.jsp.tagext
d. javax.servlet.jsp.tagext
16. Choose the order of the events in which they occur when the JSP page is requested by the user.
1. jspinit is called
2. JSP page implementation class is loaded
3. JSP page is compiled
4. jspDestroy is called
5. JSP page implementation is instantiated
6. JSP page is translated
7. _jspservice is called
a. 6 3 2 5 1 7 4
b. 6 3 2 5 1 4 7
c. 6 2 3 5 1 7 4
d. 6 5 2 3 1 7 4
17.
Data types from the following options

Choose the Window object properties

If an exception is thrown

In JavaScript, Objects are passed by value


Chose the JavaScript keywords from the following options

JavaScript uses prototypal or differential inheritance

The Browser Object Model


Choose the correct option that helps to get the browser

Does JavaScript allow exception handling?

Which of the following is not a valid variable name?


How do you write a conditional statement for executing

Which event occurs when the value of an element

The shift method does not


JavaScript is also called as

When we declare a variable within a function

The ___ tag is used to draw graphics


In JavaScript, Arrays are data type

Can appear in both the <head> block and within the <block>

To create an Image rollover


Joins all elements of an array

What happens if you use parseInt() to

The setInterval method


The delete operator returns a Boolean value

The loop type always runs the enclosed code at least once

When the user is working with timing


The escape() function is responsible

Javascript ignores extra spaces

Select the javascript popup boxes from the following


Data stored in an array always have to be the same data type

Does not allow you to read or write fields


Extras!!

1. The triple equal sign === checks for equal value and equal type

2. The shift method does not removes

{javascript Array: Shift() Method. The shift() method is like the pop() method, only it works at
the beginning of the array. The shift() method pulls the first element off of the given array and
returns it. This alters the array on which the method was called}

3. Javascript is also called as

4. Alert( typeof new Date() );


5. Prototypal or different inheritance – Class based programming

6. What value is returned by a function having no return


statement when it is called in JavaScript?
The default return value is undefined for a function if no return statement is present

7. What are the different loop structure available in


JavaScript?
Following are the loop structure available in JavaScript.

 while
 do-while
 For

8. What is the difference


between == and ===operators in JavaScript?
The == operator checks only the value for equality. Whereas, === checks both the value
and the data type

9. How will you select an element in the page having id


"awesome" using JavaScript?
To select an element by id we use the document.getElementById(); method.
In the following code we are selecting the element having id "awesome".

var el = document.getElementById("awesome");
10. How will you select elements in a page having class
"super" using JavaScript?
For this we will use the document.getElementsByClassName() method.
In the following example we are selecting all the elements in the page having class "super".

var elems = document.getElementsByClassName('super');

11. How will you check if a given value is not a number in


JavaScript?
For this we can use the isNaN() method which returns true if the value passed is not a number otherwise,
false.
12. Please see the below
1.Object is also called as : Component

2. which of the following is false about variable name : Variable name is not case sensitive

3. Locate first ‘X’ in the String : txt.indexof(‘X’)

4. Var mood = Joy + Happiness : Joy is added to Happiness and stored in the variable Mood

5. Var result = False && False || Truse&&True : TRUE

6. Java Script function for finding Errors: Debug

7. Built-in Object : Math

8. --------- class is used in javascript for manipulating date and time?: Date

9. An Array with Alphanumeric Index : Not Sure(Bidimensional Array)

10. Which of these is not a simple data type : Letter

11. What type of array it is [[[]]] : The Syntax is Wrong


76)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("TECHNOLOGIES","i");
document.write(qpt.match(pattern));
}
</script>
a) null
b) Technologies
c) TECHNOLOGIES
d) Error

74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer

72) <script language="javascript">


function x()
{
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","g");

document.write(pattern.exec(qpt) + " ");


document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
}

</script>
a) in in In
b) in in in
c) in in null
d) in null null
71) <script language="javascript">
function x()
{
var s = "Eat to live, but do not live to eat";
var pattern = new RegExp("eat$");
document.write(pattern.exec(s));
}
</script>
a) Eat
b) eat
c) undefined
d) Eat eat

70) <script type="text/javascript" language="javascript">


var qpt = "QualityPointTechnologies";
var result =qpt.indexOf("Tech");
document.write(result);
</script>
a) 11
b) 12
c) 15
d) 13

69) a.) var qpt="Quality Point Technologies";

b.) var qpt=new String("Quality Point Technologies");

Question:
In javascript, which of the above statement can used for string declaration ?

a) Either (a) or (b)


b) Only (a)
c) Neither (a) nor (b)
d) Only (b)
66) <script type="text/javascript">
var s = "9123456 or 80000?";
var pattern = /\d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
a) 9123
b) 91234
c) 80000
d) None of the above

60) <script type="text/javascript" language="javascript">

var qpt = "QualityPointTechnologies";


var result =qpt.substring(7,8);
document.write(result);

</script>
a) Po
b) yP
c) oi
d) P

52) <script language="javascript">


function x()
{
var qpt = "QualityPointTechnologies";
var pattern = /point/;

var output= qpt.search(pattern);

document.write("Position: " + output);


}
</script>
a) Position-7
b) Position-1
c) null
d) error

47) <script language="javascript">


function sum(x)
{
function add(y)
{
return x+y;
}
return add;
}
function callme() { result=sum(5)(5); alert(result); }
</script>

If you call the function callme(), what will happen ?


a) 10
b) Error in calling Function
c) 5
d) None of the above

46) <script language="javascript">


function x()
{
var qpt = "First come, first served";
var pattern = /first/g;
document.write(qpt.match(pattern)[1]);
}
</script>
a) first
b) First
c) undefined
d) None of the above

45) <script type="text/javascript" language="javascript">


var qpt="QualityPointTechnologies";
var result =qpt.lastIndexOf("l");
document.write(result);
</script>
a) 3
b) 18
c) 17
d) 19

43) <script language="javascript">


function x()
{
var s = "Give 100%!{[!!";
var pattern = /\W/g;
var output = s.match(pattern);
document.write(output);
}
</script>
a) ,%,!,{,[,!,!
b) G,i,v,e,1,0,0
c) Give 100
d) Error

42) (a). // , /* ...... **/


(b). / , /** ......./ , /*
(c). /*......*/ , //
(d). \*......*\ , //

In javascript, Which of the above Comments lines are used ?


a) Only (d)
b) Only (c)
c) Either (c) or (d)
d) Only (b)

41) <script language="javascript">


function x()
{
var qpt = "First come, first served";
var pattern = /first/gi;
document.write(qpt.match(pattern)[1]);
}
</script>

a) first
b) undefined
c) First
d) Error

37) <script language="javascript">


function x()
{
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","gi");

document.write(pattern.exec(qpt) + " ");


document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
}

</script>
a) in in In
b) in in in
c) in in null
d) in null null

26)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern));
}
</script>
a) Error
b) POIiNT
c) Point
d) null

24) <script language="javascript">


function x()
{
var s= "quality 100%";
var pattern = /\d/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) 100
b) 1,0,0
c) q,u,a,l,i,t,y,%
d) Error

18) <script type="text/javascript" language="javascript">


var qpt= new Array();
qpt[0] = "WebDevelopment";
qpt[1]="ApplicationDevelopment"
qpt[2]="Testing"
qpt[3] = "QualityPointTechnologies";
document.write(qpt[0,1,2,3]);
</script>
a) Error
b) QualityPointTechnologies
c) WebDevelopment
d) WebDevelopmnet,ApplicationDevelopment,Testing,QualityPointTechnologies

17) <script language="javascript">


function x()
{
var s = "Quality 100%!{[!!";
var pattern = /\w/g;
var output = s.match(pattern);
document.write(output);
}
</script>
a) %,!,{,[,!,!
b) Q,u,a,l,i,t,y,1,0,0
c) Quality 100
d) Error

13) <script language="javascript">


function x(z,t)
{
alert(x.length);
}
< /script>
output:
?
a) Error
b) 2
c) 1
d) 3

12) Syntax for creating a RegExp object:


(a). var txt=new RegExp(pattern,attributes);
(b). var txt=/pattern/attributes;
Which of the above mentioned syntax will correct?
a) (a) only
b) (b) only
c) Both (a) and (b)
d) None of the above

9) <script language="javascript">
var qpt="QUALITY POINT TECHNOLOGIES";
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error

8) <script language="javascript">
function x()
{
var s= "Good 100%";
var pattern = /\D/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error

2) <script type="text/javascript" language="javascript">


var qpt = "Qualiyt Point Technologies";
var result = qpt.split(" ");
document.write(result);
</script>
a) Quality
b) Q,u,a,l,i,t,y,P,o,i,n,t,T,e,c,h,n,o,l,o,g,i,e,s
c) Qualiyt,Point,Technologies
d) QualityPointTechnologies

1) <script type="text/javascript">
x=4+"4";
document.write(x);
</script>
Output------?
a) 44
b) 8
c) 4
d) Error output

60. <script type="text/javascript">


var s = "9123456 or 80000?";
var pattern = /\d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
A. 9123
B. 91234
C. 80000
D. None of the above
76)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("TECHNOLOGIES","i");
document.write(qpt.match(pattern));
}
</script>
a) null
b) Technologies
c) TECHNOLOGIES
d) Error

74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer

72) <script language="javascript">


function x()
{
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","g");

document.write(pattern.exec(qpt) + " ");


document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
}

</script>
a) in in In
b) in in in
c) in in null
d) in null null
71) <script language="javascript">
function x()
{
var s = "Eat to live, but do not live to eat";
var pattern = new RegExp("eat$");
document.write(pattern.exec(s));
}
</script>
a) Eat
b) eat
c) undefined
d) Eat eat

70) <script type="text/javascript" language="javascript">


var qpt = "QualityPointTechnologies";
var result =qpt.indexOf("Tech");
document.write(result);
</script>
a) 11
b) 12
c) 15
d) 13

69) a.) var qpt="Quality Point Technologies";

b.) var qpt=new String("Quality Point Technologies");

Question:
In javascript, which of the above statement can used for string declaration ?

a) Either (a) or (b)


b) Only (a)
c) Neither (a) nor (b)
d) Only (b)
66) <script type="text/javascript">
var s = "9123456 or 80000?";
var pattern = /\d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
a) 9123
b) 91234
c) 80000
d) None of the above

60) <script type="text/javascript" language="javascript">

var qpt = "QualityPointTechnologies";


var result =qpt.substring(7,8);
document.write(result);

</script>
a) Po
b) yP
c) oi
d) P

52) <script language="javascript">


function x()
{
var qpt = "QualityPointTechnologies";
var pattern = /point/;

var output= qpt.search(pattern);

document.write("Position: " + output);


}
</script>
a) Position-7
b) Position-1
c) null
d) error

47) <script language="javascript">


function sum(x)
{
function add(y)
{
return x+y;
}
return add;
}
function callme() { result=sum(5)(5); alert(result); }
</script>

If you call the function callme(), what will happen ?


a) 10
b) Error in calling Function
c) 5
d) None of the above

46) <script language="javascript">


function x()
{
var qpt = "First come, first served";
var pattern = /first/g;
document.write(qpt.match(pattern)[1]);
}
</script>
a) first
b) First
c) undefined
d) None of the above

45) <script type="text/javascript" language="javascript">


var qpt="QualityPointTechnologies";
var result =qpt.lastIndexOf("l");
document.write(result);
</script>
a) 3
b) 18
c) 17
d) 19

43) <script language="javascript">


function x()
{
var s = "Give 100%!{[!!";
var pattern = /\W/g;
var output = s.match(pattern);
document.write(output);
}
</script>
a) ,%,!,{,[,!,!
b) G,i,v,e,1,0,0
c) Give 100
d) Error

42) (a). // , /* ...... **/


(b). / , /** ......./ , /*
(c). /*......*/ , //
(d). \*......*\ , //

In javascript, Which of the above Comments lines are used ?


a) Only (d)
b) Only (c)
c) Either (c) or (d)
d) Only (b)

41) <script language="javascript">


function x()
{
var qpt = "First come, first served";
var pattern = /first/gi;
document.write(qpt.match(pattern)[1]);
}
</script>

a) first
b) undefined
c) First
d) Error

37) <script language="javascript">


function x()
{
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","gi");

document.write(pattern.exec(qpt) + " ");


document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
}

</script>
a) in in In
b) in in in
c) in in null
d) in null null

26)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern));
}
</script>
a) Error
b) POIiNT
c) Point
d) null

24) <script language="javascript">


function x()
{
var s= "quality 100%";
var pattern = /\d/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) 100
b) 1,0,0
c) q,u,a,l,i,t,y,%
d) Error

18) <script type="text/javascript" language="javascript">


var qpt= new Array();
qpt[0] = "WebDevelopment";
qpt[1]="ApplicationDevelopment"
qpt[2]="Testing"
qpt[3] = "QualityPointTechnologies";
document.write(qpt[0,1,2,3]);
</script>
a) Error
b) QualityPointTechnologies
c) WebDevelopment
d) WebDevelopmnet,ApplicationDevelopment,Testing,QualityPointTechnologies

17) <script language="javascript">


function x()
{
var s = "Quality 100%!{[!!";
var pattern = /\w/g;
var output = s.match(pattern);
document.write(output);
}
</script>
a) %,!,{,[,!,!
b) Q,u,a,l,i,t,y,1,0,0
c) Quality 100
d) Error

13) <script language="javascript">


function x(z,t)
{
alert(x.length);
}
< /script>
output:
?
a) Error
b) 2
c) 1
d) 3

12) Syntax for creating a RegExp object:


(a). var txt=new RegExp(pattern,attributes);
(b). var txt=/pattern/attributes;
Which of the above mentioned syntax will correct?
a) (a) only
b) (b) only
c) Both (a) and (b)
d) None of the above

9) <script language="javascript">
var qpt="QUALITY POINT TECHNOLOGIES";
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error

8) <script language="javascript">
function x()
{
var s= "Good 100%";
var pattern = /\D/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error

2) <script type="text/javascript" language="javascript">


var qpt = "Qualiyt Point Technologies";
var result = qpt.split(" ");
document.write(result);
</script>
a) Quality
b) Q,u,a,l,i,t,y,P,o,i,n,t,T,e,c,h,n,o,l,o,g,i,e,s
c) Qualiyt,Point,Technologies
d) QualityPointTechnologies

1) <script type="text/javascript">
x=4+"4";
document.write(x);
</script>
Output------?
a) 44
b) 8
c) 4
d) Error output

60. <script type="text/javascript">


var s = "9123456 or 80000?";
var pattern = /\d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
A. 9123
B. 91234
C. 80000
D. None of the above

You might also like