103
1 Code timeout=setTimeout("updateTimeStamp();",5000); 1 – 10 Which one of the following is true of the code segment above? It causes setTimeout() to initialize the date and time library. It fires an event to invoke updateTimeStamp() every five seconds. It creates a Time object that ticks once every 0.5 seconds. It fires an event to invoke updateTimeStamp() in five seconds. It adds an onTimeOut event handler to the document. Ans: It fires an event to invoke updateTimeStamp() in five seconds. Code setTimeout("cycle()",3 * 3000); How often is function cycle() called in the above code? 3 milliseconds 3.003 seconds 3000 milliseconds 9 seconds 9000 seconds Ans: 9 seconds Date: 4/26/2009 Time: 10:13:9 currentDate = new Date() with (currentDate) { document.write("Date: "+getMonth() + "/"+getDate()+"/"+getYear()+"<BR>")

Javascript

Embed Size (px)

Citation preview

1Code timeout=setTimeout("updateTimeStamp();",5000); 1 10 Which one of the following is true of the code segment above? It causes setTimeout() to initialize the date and time library. It fires an event to invoke updateTimeStamp() every five seconds. It creates a Time object that ticks once every 0.5 seconds. It fires an event to invoke updateTimeStamp() in five seconds. It adds an onTimeOut event handler to the document.

Ans:

It fires an event to invoke updateTimeStamp() in five seconds.

Code

setTimeout("cycle()",3 * 3000); How often is function cycle() called in the above code? 3 milliseconds 3.003 seconds 3000 milliseconds 9 seconds 9000 seconds Ans: 9 seconds

Date: 4/26/2009 Time: 10:13:9

currentDate = new Date() with (currentDate) { document.write("Date: "+getMonth() + "/"+getDate()+"/"+getYear()+"
") document.write("Time: "+getHours() + ":"+getMinutes()+":"+getSeconds()) } What is the output of the code above in the user's browser? (Assume user time is Thursday July 9, 2003, and the current time is 3:30:33 P.M. EST) Date: July/9/2003 Time: 3:30:33 Date: July/9/03 Time: 15:30:33 Date: 6/9/2003 Time: 15:30:33 Date: 7/9th/2003 Time: 3:30:33 Date: July/9th/2003 Time: 15:30:33

2 ANS:Date: 6/9/2003 Time: 15:30:33

Which one of the following is true of the "Math" object? It must be instantiated with Math(base) before any methods are used. It provides methods and properties for various arithmetic operations. It holds the base (10, 16, e, etc.) used in mathematical operations. It holds string properties containing all arithmetic symbols. It performs common vector-based drawing functions. ANS: It provides methods and properties for various arithmetic operations. What code asks if the user wants a greeting and, if so, displays "wel.gif" and writes "Welcome!" in the document window? if (confirmed("OK to welcome?")) { alert.write(); alert.write(
Welcome!); } if (confirmed("OK to welcome?")) { alert(''); alert("
Welcome!"); } if (confirm("OK to welcome?")) { document.write(''); document.write("
Welcome!"); } if (confirm("OK to welcome?")) { document.write(); document.write(
Welcome!); } if (confirm("OK to welcome?")) { document.write(); alert(
Welcome!); } Ans : Option 3 if (confirm("OK to welcome?")) { document.write(''); document.write("
Welcome!"); }

Sample Code

document.TestForm.TestSelect.options[1].selected = true; What does the above code do? It selects the first option in the TestForm on the TestSelect. It deselects the first option in the TestSelect on the TestForm. It deselects the second option in the TestSelect on the TestForm. It selects the second option in the TestSelect on the TestForm. It selects the first option in the TestSelect on the TestForm. Ans: It selects the second option in the TestSelect on the TestForm.

3

How do you change the document in the second frame to "test.html"? top.frames[2].url = "test.html"; self.frames[1].url = "test.html"; self.frames[2].location.href = "test.html"; self.frames[1].href = "test.html"; self.frames[1].location.href = "test.html";

ANS:

self.frames[1].location.href = "test.html";

The event method "setTimeout(code, time)" is a method belonging to which one of the following objects? document location window form It does not belong to any object.

ANS:

window

Which one of the following statements is true? Global variables must be used first in order to let the browser know to initialize it. Global variables must be declared in an outside file. Global variables are properties of a global object. Global variables are always constants. Global variables are inaccessible from more than one window. ANS: Global variables are properties of a global object.

Which one of the following methods may need privileges? escape(s) document.clear() form.submit()

4navigator.javaEnabled() self.close()

ANS:

navigator.javaEnabled()

if (navigator.javaEnabled()) { function1() } else function2() .... a preference with the preference method requires the UniversalPreferencesRead privilege. ...

Sample Code

What does x contain if the user presses "OK" on the confirm dialog above? 'OK' true 1 A reference to the confirm dialog 'Is it OK?'

ANS: true

What does window.length return? The length in pixels The number of open windows The length as a percentage of screen size The number of open browser windows The number of frames in the window

ANS:

The number of frames in the window

Sample Code

var i = 0, j = 0; for ( ; i < 10; i++) j += ++i; After the above code segment is run, what will be the values of 'i' and 'j'?

5i = 12, j = 36 i = 11, j = 36 i = 10, j = 36 i = 11, j = 25 i = 10, j = 25

ANS:

i = 10, j = 25

If a window contains only two sibling frames, which one of the following is equivalent to "parent" within one of those frames? document frames top window self

ANS:

top

Code

var total=0; for(var j=0;j 1) * (z

11 Referring to the above, which code fragment loads i with the value of the second array element? i = o.array(2); i = o.prototype.array[2]; i = o.array["1"]; i = o.prototype.array[1]; i = o.array(1);

ANS:

i = o.array["1"];

What code removes every 'x' from String "S"? var myArray = S.clear('x'); S = myArray.join(''); var SCopy = ''; for(var i = 0; i < S.length; i++) if(S.charAt(i)!='x') {SCopy += S.charAt(i); S = SCopy; while(i=1;i Referring to the above, what happens when the "On" checkbox is checked for the first time? The "Off" checkbox is checked. The "On" checkbox is unchecked. The "Off" checkbox is reversed. The "Off" checkbox is unchecked. Nothing happens.

ANS: Nothing happens.

22Sample Code Where do the results from submitting the above form go? To a new window To a target named 'frame2' To the topmost window To a target named 'frame1' To the same frame in which the form is

ANS:

To a target named 'frame2'

To a target named 'frame1'

Code

var s = "test"; s.big(); s.blink(); s=s.bold(); s=s.strike(); s=s.fontsize(7); document.write(s.italics()); Referring to the above code, the html document shows the word "test" with what style characteristics? Blinking, bold, strikethrough, size 8, and italic Default styles for browser Bold, strikethrough, size 7, and italic Size 7 and italic Italic

ANS:

Bold, strikethrough, size 7, and italic

Code

var i=0; for(j=0;j Referring to the sample code above, which one of the following functions assigns another value to the hidden input? function changeValue(f){ var j = prompt("New Value", ""); f.hiddenInput = j; } function changeValue(f){ var j = prompt("New Value", ""); f[hiddenInput].value = j; } function changeValue(f){ f[hiddenInput] = prompt("New Value", ""); } function changeValue(f){ f.hiddenInput.value = prompt("New Value", ""); } function changeValue(f){ var j = prompt("New Value", ""); f.forms.hiddenInput.value = j; }

ANS: function changeValue(f){ f.hiddenInput.value = prompt("New Value", ""); }

Q:Which

one of the following is true of an event?

It is the execution of any function. It is a signal generated when a specific action occurs. It is the start of any script block execution. It is a user-generated action. It is the execution of any script statement.

ANS:It is a signal generated when a specific action occurs.

Sample Code

var x = 0; var y = 3; Referring to the above code, which one of the following is true? x == y - 3 x=y y0

39y * -3 > 0 ANS: x == y - 3

Sample Code

Option 1 Option 2 Option 3 Option 4

Q:

function surfto(form) { var idx=form.s1.selectedIndex if(form.s1.options[idx].value != 0) location=form.s1.options[idx].value; } Choose One U2 U3 U4

Pull down with 4 choices

Which property is used to access the number of elements in a form? elements method length count

40number ANS: length

Sample Code

var testVar = Math.ceil(Math.random() * 100); Referring to the above, what is range of variable "testVar"? -99 to 100 0 to 99 0 to 100 1 to 99 1 to 100 ANS: 1 to 100

41

Generally speaking, the "onUnload" event handler is used to do which one of the following? Choice 1 Choice 2 Choice 3 Choice 4 Choice 5 Remove a document from browser cache Unload an HTML document Perform actions after a document is unloaded Perform actions before a document is unloaded Close a window or frame objects

(I think itz answer is option 5 please verify- Pooja) Perform actions before a document is unloaded

42Home Order Resellers Contact us You are here: Duckware Java Applets Reference Web tips About Shareware JavaTM Applet Reference PMVR 1. The Java HTML Tag SlideShow 2. Applet Security Model GoRound 3. Technical Notes Java Tools JexePack Jobfuscate 1. MakeInstall The Java HTML Tag Affordware Bug Free C param name=parameter2 value=value2> Space Rocks . . . alternateHTML

Contact us

To embed any Java applet within an HTML web page, you must use the tag. See the table to the right for the tag syntax (grayed options are optional; bold text is used as-is; italic text is information that you must provide). code=class-filename -code="pmvr.class" -- The filename of the applet to load (which always ends in .class). It will load from the directory/folder listed by the codebase attribute listed below. width=pixels -- width=500 -- The width, in pixels, of the applet. This may also be a percentage, like 20%, but rarely is. height=pixels -- height=250 -- The height, in pixels, of the applet. This may also be a percentage, like 20%, but rarely is.

archive=jar-file -- archive="pmvr.jar" -- The name of a jar file, which contains the *.class files for you applet. Note that files in the JA must be in stored format (no compression). Otherwise, if you use compression, you limit yourself to Java 1.1 or later compatibility.

instance-name -- name="pmvr" -- Your name for the applet, which can be any text that makes sense to you. This allows applets within web page to find each other and it allows for you to control the applets via JavaScript. This attribute is optional.

codebase=url -- codebase=".." -- The URL to the directory/folder containing the applet code (class files). An absolute URL can be specified (useful for hosting PMVR tours on multiple domains). A relative URL allows the applet to work on both web servers and the local file system. relative URL is relative to the document's base URL defined by the BASE tag. If the document does not define a BASE tag, it is relative to the directory/folder containing the HTML file.

align=alignment -- align="left" -- The alignment of the applet. It behaves (and has the same options) as the IMG tag align attribute. Th attribute is optional.

vspace=pixels -- vspace=3 -- The vertical space, in pixels, between the applet and surrounding text. It behaves the same as the IMG tag vs attribute. This attribute is optional.

hspace=pixels -- hspace=3 -- the horizontal space, in pixels, between the applet and surrounding text. It behaves the same as the IMG tag hspace attribute. This attribute is optional.

MAYSCRIPT -- This attribute allows you to use JavaScript within an applet. If you want to use JavaScript, you must grant the applet access to JavaScript by using the MAYSCRIPT attribute, otherwise the applet is not permitted to use JavaScript. If you use MAYSCRIPT on one applet in web page, you will need to use MAYSCRIPT on all applets in the web page. Please refer to the 12/30/1999 tech note [3] for details.

43

-- Applet parameters are used to configure an applet. Just use as many param tags as needed to configure the parameters (the parameters are always specific to the particular applet you are using). Please note that param tags are defined within the APPLET tag.

AlternateHTML -- If the tag is not supported by a web browser, the HTML in this section will be displayed. Otherwise, the applet is shown and the HTML in this section is ignored. For more information about the tag, visit Sun's Applet tag reference.

2. The Java Applet Security Model A Java VM (virtual machine) is what allows Java applets to run within web browsers. And all modern web browsers come with a Java VM. Jav applets are safe to run on your computer because the Java VM prevents a Java applet from accessing resources (files/network/memory/etc) is not authorized to access. Applets can be run in a web browser either from a web server, or from the local file system (disk/CD). Web Server: When a Java VM runs a Java applet from a web server, the Java applet is authorized to access any file on the web server that applet came from, but the applet can not access any file on another web server or any file on the local file system (your PC).

Local File System: However, when a Java VM runs a Java applet from a local file system (your hard drive), the Java applet is authorized to access only files in the directory that the applet came from (or any subdirectories). Also, the Java VM prevents an applet from accessing files root of any drive/CD, as detailed in the 06/20/2000 tech note [3], as operating system (OS) configuration files (config.sys, autoexec.bat are usually located there.

For example, the following table summarizes what an applet, running from an HTML file test.html in the tours directory (with the class file placed in the same tours directory) is allowed to access: Can an applet in test.html (in tours folder) access... this image when run from ../pan1.jpg ../images/pan2.jpg ./pan3.jpg ./images/pan4.jpg http://www.xyz.com/any.jpg http://www.xyz.com/tours/ c:/tours/ yes yes yes yes NO NO NO yes yes NO

Notice the discrepancy in access to pan1.jpg and pan2.jpg. Depending upon where test.html is accessed from (a web server or the local h drive), access to the same image can be either allowed or denied. The problem is that running from the local hard drive is more restrictive th running from a web server. Because when running from a local hard drive, only files in the same directory as the applet class files (or subdirectories) can be accessed by the applet.

With proper planning, and by using the Java applet codebase tag, this problem can be avoided. Namely, create all tours within a directory tr use the codebase attribute within any tags [1] in HTML to refer back to the one set of Java class files in the root of the directory you created.

3. Java Applet Technical Notes Java Console TIP: If you are experiencing problems with an applet, the first step is to open the 'Java Console' in your browser to check for messages:

Internet Explorer (Sun's Java): The Java Console option appears under the Tools menu. Firefox: Right click on the Java tray icon and select 'Java Console'.

Netscape Communicator: The Java Console is located in the 'Tools / Web Development' menu (or under 'Communicator' menu in older versions). Internet Explorer (Microsoft Java): The Java Console must first be enabled in 'Tools / Internet Options / Advanced / Microsoft VM / Java console enabled'. After restarting your browser, the 'Java Console' option will be available the 'View' menu.

03/28/2006 -- Activating ActiveX Controls (Java) in Internet Explorer -- Microsoft has changed how user's interact with ActiveX (Ja controls on web pages. Previously, you could interact immediately with controls. However, now there is an extra click. Full details and a workaround. NOTE: the need for this extra click has been removed by Microsoft in April 2008.

44

01/04/2006 -- Internet Explorer on Mac should no longer be used -- Microsoft's Internet explorer for the Mac is no longer a product Apple's Safari web browser should be used instead.

02/19/2001 -- Java Applets Cannot Be JavaScript'ed in Mac Internet Explorer -- Microsoft Article ID Q190283 has complete detail summary, Microsoft does not support JavaScript to Java communication on the Mac. However, please note that Netscape on the Mac and App Safari web browser both do support scripting. To work around this problem, use a web browser that works, or use Native scripting instead of JavaScript scripting.

10/30/2000 -- Do not use spaces in filenames -- Do not use spaces in the filenames of images, etc (possible under a Windows server) appears that this can cause problems with some browser / server combinations. Namely, using a URL with a space works under IE (the space automatically converted to %20), but fails under Netscape.

09/08/2000 -- Netscape cannot read some JPEGs -- Some people have reported that a panorama displays fine in Internet Explorer, bu does not appear when using Netscape Navigator (and that the Netscape java console window reports a "sun.awt.image.ImageFormatExcep Image too wide for this implementation" error). This particular problem has been traced to Netscape being unable to read the JPEG at test this, create a URL that points directly to the JPEG image file on the server and test under both Netscape and Internet Explorer. If it does appear in Netscape but it does within Internet Explorer, then you have run into this problem. The graphics program you are using is producin JPEG that Netscape is unable to read! Whether this is a problem with the program you are using to write the JPEG (but Internet Explorer wor with Netscape is unknown. The work-around is to use another graphics program to write the JPEG.

06/24/2000 -- Avoid using transparent GIF images -- Make sure that you avoid using transparent GIF images in applets, if possible. I appears that many Java VM's take a significant performance hit in order to display transparent GIF images. While transparent GIF images do they may dramatically show down the applet and cause jerky displays.

06/20/2000 -- Files in the root of a drive/CD cause security errors -- If you attempt to locate class or image files into the root direc of a drive or CD, you will experience problems due to the Java applet security model [2] (that prevents applets from accessing the root of a or CD). The work-around is to move your class files and images into a directory/folder.

12/30/1999 -- MAYSCRIPT and Netscape -- If you use the MAYSCRIPT applet tag on one applet, you must use the MAYSCRIPT tag on applets on a web page. This is due to a bug in the Netscape web browsers. If you use MAYSCRIPT in only one applet, a second applet can no longer communicate with the first. Please note that this bug only exists in the Netscape browsers and not in the Microsoft browsers. Copyright 2000-2009 Duckware The "MAYSCRIPT" attribute of the HTML element is used to do which one of the following? To To To To To create an applet end a script when an error occurs convert a script to binary code replace an applet with an equivalent script give a Java applet access to a JavaScript script

ANS- To give a Java applet access to a JavaScript script Which one of the following is a correct way to create an instance of a Function object? funct funct funct funct funct = new.Function() = new.Function = Function(new) == Function = new Function()

ANS: funct = new Function()

45

Sample Code

4) break iloop; if (j > 3) break jloop; } } // --> What are the values of I and j after execution of the above code? i = 4, j = 4 i = 4, j = 3 i = 5, j = 4 i = 5, j = 3

46i = 5, j = 5 ANS: i = 5, j = 4

Sample Code

var x; x = 5 * 5 * 5 * 5 * 5; Which one of the following is equivalent to the code above? x = 5 + 5 + 5 + 5 + 5; x = 5 ^ 5; x = 5.toPower(5); x = Math.pow(5,5); x = Math.toPower(5,5); ANS: x = Math.pow(5,5);

Which one of the following code samples changes the method of TestForm to "GET"? document.TestForm.method = "GET"; document.TestForm.onsubmit = "GET"; document.TestForm.method("GET"); document.TestForm.onsubmit("GET"); document.TestForm.setMethod("GET"); ANS: document.TestForm.method = "GET"; Sample Code function openWindow(x, y, z) { window.open(x, y, z); } When called, the above function opens a new window with which of the following? A URL of "y," a title of "z," and features of "x." A URL of "x," a title of "y," and features of "z." A URL of "y," a title of "x," and features of "z." A URL of "z," a title of "y," and features of "x." A URL of "x," a title of "z," and features of "y." ANS: A URL of "x," a title of "y," and features of "z."

Sample Code What does the above code create? Five checkboxes and a button that loads the selected document when clicked Five hyperlinks A pull-down menu and a button that loads the selected document when clicked Five buttons, each loading a corresponding URL when clicked Five radio buttons and a button that loads the selected document when clicked ANS: Five buttons, each loading a corresponding URL when clicked

Sample Code

c) x += 1; (a > (b + c)) x += 1; ((b > c) && (c > a)) x += 1; ((c > a) || (b > c)) x += 1;

// --> What is the value of x after the above script is run? 1 2 3 4 5

48

ANS:2

Sample Code

var newWindow = open(url, title, args); To which one of the following does newWindow.opener refer in the above code? newWindow itself The window that opened newWindow The URL with which newWindow is opened The top window The navigator object ANS: The window that opened newWindow

The opener property returns a reference to the window that created the windowThe referrer property returns the URL of the document that loaded the current document

The items in which one of the following pairs do the same thing? history.go( history.length) and history.go(0) history.forward() and history.go() history.go(-2) and history.back() history.back() and history.go(-1) history.forward(1) and history.go(0)

ANS: history.back() and history.go(-1)

Which one of the following is true of local variables? They are always in scope. They are declared using the "var" command. They are not accessible to sub-blocks. They are only referenced inside the block in which they are declared. They are accessible throughout the JavaScript code. ANS: They are only referenced inside the block in which

49they are declared.

Output

One, Two.. What code produces the above output? document.write("One,\nTwo..\n"); document.write('One,\nTwo..\n'); document.write('One,\nTwo..\n'); document.writeln("One,'); document.writeln('Two '); document.writeln('One,');document.write('Two '); ANS: document.write('One,\nTwo..\n');

Code

txt = new String("Sample text."); function textColor() { return "" + this + ""; } Using the code above, what code assigns a "color" property to all string objects defaulted "gray" and facilitates printing colored text to a browser? String.color = "gray"; String.colored = textColor; color.String = "gray" String.txt.color = "gray" String.color = "gray" String.prototype.color = "gray"; String.prototype.colored = textColor; ANS: String.prototype.color = "gray"; String.prototype.colored = textColor;

Code

function calc(form,fld) { var d = 0; if(fld == "r") { if(form.s.checked) { d=Math.sqrt(form.r.value); } else { d=form.r.value/2; } } else { if (form.s.checked) { d = form.e.value * form.e.value; } else { d = form.e.value * 2; } } return d; } Referring to the above code, if checkbox "s" is checked, and parameter "fld" is equal to "q," what does function calc return?

50"e" squared "r" * 2 null "r"/ 2 square root of "e" ANS: "e" squared

Q: // --> Referring to the above, which one of the following code fragments will output the value of x? window.output(x); document.output(x); window.writeln(x); window.document.writeln(x); String.output(x); ANS: window.document.writeln(x);

Q: In the above code, to which one of the following does "this" refer? document textObject checkText form window ANS:FORM

51

Q: i=0; total=0; while(i 2) break; total += i; } What is the value of "total" after execution of the code above? 0 1 2 3 6 ANS:3

Q:If you wanted to put "Hello There!" on the status line, which one of the following code fragments does that? self.status = "Hello There!"; return true; self.status.value = "Hello There!"; return true; self.document.status.setValue("Hello There!"); return true; self.status.setValue("Hello There!"); return true; self.setStatus("Hello There!"); return true; ANS: self.status = "Hello There!"; return true;

52

53

1. 'url to open'

This is the web address of the page you wish to appear in the new window. 2. 'window name' You can name your window whatever you like, in case you need to make a reference to the window later. 3. 'attribute1,attribute2' As with alot of other things, you have a choice of attributes you can adjust.

Window Attributes

54

Below is a list of the attributes you can use:1. width=300

Use this to define the width of the new window.2. height=200

Use this to define the height of the new window.3. resizable=yes or no

Use this to control whether or not you want the user to be able to resize the window.4. scrollbars=yes or no

This lets you decide whether or not to have scrollbars on the window. 5. toolbar=yes or no Whether or not the new window should have the browser navigation bar at the top (The back, foward, stop buttons..etc.). 6. location=yes or no Whether or not you wish to show the location box with the current url (The place to type http://address). 7. directories=yes or no Whether or not the window should show the extra buttons. (what's cool, personal buttons, etc...). 8. status=yes or no Whether or not to show the window status bar at the bottom of the window. 9. menubar=yes or no Whether or not to show the menus at the top of the window (File, Edit, etc...). 10. copyhistory=yes or no Whether or not to copy the old browser window's history list to the new window.

Q:Site Map Which one of the following is true of the above code? It opens a new status window with document text "Click for Help!" It creates a hyperlink that says "Click for Help!"

55Most browsers will interpret this as a syntax error. It displays a help message in the status bar when mouse is over the hyperlink. It does nothing because the JavaScript language is not specified.

ANS: It displays a help message in the status bar when mouse is over the hyperlink.

Which event handler or handlers are used to track a user's moves between fields in an HTML form? onFocus and onBlur onChange focus and blur load and unload

onLoad and onUnloadANS: onFocus and onBlur

Q:To delete an element from an array of Option objects attached to a DOM Selectobject, you set its reference equal to which one of the following? -1 null 0 NaN

false

ANS; null

56

Q:var x; var y; x = new Array(3); x[0] = 1; x[1] = 2; x[2] = 3; y = new Array(3); y[0] = 1; y[1] = 2; y[2] = 3;Referring to the above, which one of the following is true? x.toString() == y.toString() x.equals(y) x == y x equals y

None of the aboveANS: x.toString() == y.toString()

Which one of the following is a DRAWBACK of JavaScript? It cannot be copy-protected. It does not work with Html forms. It is platform independent. It only works with Netscape browsers.

It does not work with CGI. ANS: It cannot be copy-protected.

57

Q:var index = 0; do { index++; document.writeln(index); } while (index < 10);Which one of the following code segments is equivalent to the code above?

1. var index = 1; do { document.writeln(++index); } while (index Option 1 Option 2 Option 3 What does the above script do in Internet Explorer?

It changes the title of the top level document to the value of the selected option. It changes the title of the document in all open browser windows. It outputs the selected title to the document's window. It changes the selected index to the value of the selected option.

It changes the title of the document in the current frame.

64 Ans: It changes the title of the top level document to the value of the selected option How can you get the width of the user's screen in JavaScript? self.getWidth() self.width self.screen.width

self.document.getWidth() self.get("width")ANS:Self.width

self.screen.widthSample Code function test(x, y) { return (Math.sqrt(x*x + y*y)); } function test2(x, y) { return (x ^ y); } document.writeln(test2(test(3,4),3)); What does the above code print? 2 4 6 25 125 ANSWER:6

Code

var x=0; var y=0; var z=0; x = 1; x = (-x + y++) * ++z; What is the value of "x" after execution of the code above? -2 -1 0 1 2 ANSWER:-1

65

Q:For which one of the following is the default keyword used? To create a default function To import the default style for the document To execute the default code in a switch statement To specify a default document if an href is incorrect To use the default JavaScript files for the site ANSWER: To execute the default code in a switch statement

Sample Code

What does the above code do? It loads up errorpage.html when the page with this script is first loaded. If there is an error in the document, it loads up errorpage.html. It creates an error because the window object does not have an onerror property. If there is an error in any window, it loads up errorpage.html. It creates an error because the self object does not have an onerror property.

ANSWER: If there is an error in the document, it loads up errorpage.html.Code var sample = "test"; sample.big().blink().bold().strike(); sample=sample.fontsize(7); document.write(sample.italics()); Referring to the above code, the document shows the word "test" with what style characteristics? Size 7, blinking, bold, strikethrough, and italic Size 7 and italic only Italic only Blinking, bold, strikethrough, size 8, and italic Default for the document

66ANSWER: Size 7 and italic only

Sample Code

var season; /* code segment */ switch (season) { case 1: document.writeln("Winter"); break; case 2: document.writeln("Spring"); break; case 3: document.writeln("Summer"); break; case 4: document.writeln("Autumn"); } Which one of the following code segments always will output "Summer" in the code above? season = 4; season = Math.ceil(Math.random() * 4); season = "Winter"; season = Math.ceil(Math.random()) * 3; season = "Summer"; ANSWER: season = Math.ceil(Math.random()) * 3;

var test = "Navigator"; test=test.substring(3,0); Referring to the above code, what is the value of "test" after execution? Nav Naviga iga tor igator ANSWER: NAV

Q: function echo(form,currentfield) { if(currentfield == "first") form.second.value=form.first.value; else form.first.value=form.second.value; } Function echo() above does which one of the following? It copies the text from the second field to the first.

67It moves the text from the second field to the first. It moves the text from the first field to the second. It swaps the text entered between fields. It copies the text from the first field to the second. ANSWER: It copies the text from the first field to the second. It swaps the text entered between fields What does the referrer property of the document object contain? The history object The URL that linked to the current document The current URL The URL in the URL line in the browser The name of the window that opened the document

ANSWER: The URL that linked to the current document

What does the value of a reset button contain? The button object The button label The button type The reset property The button name The button label

JavaScript Features

A can not directly access client computer resources B can not collect or give out passwords C can not access other computers remotely D uses 40 bit encryption Referring to the above code, JavaScript security is enhanced because of which one of the following pairs? A and B B and C C and D A and C

68B and D

ANS: A and C

What properties contain the name and version of the browser in use? document.cookie navigator.appName and navigator.appVersion document.host and document.hostVersion browser.name and browser.version This information is not readily available.

ANS:

navigator.appName and navigator.appVersion

Code

test Referring to the above code, when the "onMouseOver" event fires, the status line displays which one of the following? The word "test" The current document URL with "Example" after it The current document URL with a "#" after it The word "Example" The "#" symbol

ANS: The current document URL with a "#" after it The word "Example"

The alert method belongs to which object? location document window It does not belong to any object. input

ANS: window

69Code function wContent(thisPage) { parent.content.document.write(""); parent.content.document.write("Page "+ thisPage+"."); parent.content.document.close(); } Referring to the above code, what code writes content into the main window? Page1 Page1 Page1 Page1 Page1 ANS: Dont know Page1

num = 0; while(num Option 1 Option 2 Option 3 Option 4 Option 5 Given the above, what is the value of document.TestForm.TestSelect.length? 1 2 3 4 5

ANS: 5

How do you create a new DOM cookie? Clone another cookie. Call document.newCookie(). Assign values to the document.cookie property. Reset the expiration date on an existing cookie. Call newCookie(). ANS: Assign values to the document.cookie property.

Sample Code

Where does clicking the submit button in the above code take you?

77"somewhere.on.net" main page "somewhere.on.net" main page, then back three pages Back three pages Back three pages, then to the "somewhere.on.net" main page It will give a JavaScript error. ANS: Back three pages

Which one of the following is NOT a JavaScript method used to emulate an event? submit() select() load() focus() click() ANS: submit() ??

Code

function loadOver() { code here } Referring to the above code, what statement inside function loadOver() causes button "Reload" to emulate the Refresh button of a browser? parent.ctr.location="javascript:location.reload()" self.counter.location="location.history(0)" location.reload() document.location.href = this parent.history(0) ANS: location.reload()

Sample Code

var x = 1; x = new Function("x", "y", "return 4;"); What is the value of x.length after executing the above code segment? 0 1 2 3 4 ANS: 2

78

What do server-side session objects generally use on the client side to keep track of the user's session? document.referrer document.session The history object. cookies The window object.

ANS: cookies Cookies and Sessions - Session variables are maintained as cookies on the client so the client browser must have cookies enabled in order for the server to maintain session variables, otherwise the server sees every access by the same client as a new session when cookies are disabled. The server script can test whether session state is being maintained (i.e. cookies enabled) by: 1. setting a session variable, 2. immediately invoke another ASP that tests if the session variable is still defined, 3. if not defined then most likely the browser isn't accepting cookies.

What code captures the user's name, or "Name," if the user clicks OK WITHOUT entering a name? alert("Hello, " + confirm("Enter Your Name:")) alert("Hello, " + alert("Enter Your Name:")) alert("Hello, " + prompt("Enter Your Name:","Name") + ".") prompt("Hello, " + prompt("Enter Your Name:","Name") ".") alert("Hello, ") + prompt("Enter Your Name:") ANS: alert("Hello, " + prompt("Enter Your Name:","Name") + ".")

document.write(''); document.writeln("
Test"); document.write("JS!"); Which one of the following is equivalent to the above code?

79document.writeln(Test\nJS!) document.write('
Test\nJS!') document.writeln('')
Test\nJS! document.write('
Test\nJS! ') document.write("Test\nJS!")

ANS: document.write('
Test\nJS! ') Which one of the following is the form object's only method? send() submit() click() focus() select() ANS: submit() What code always brings window "newWindow" to the front? newWindow.position(top) newWindow.focus() setPosition.newWindow.top newWindow.Visibility(top) onFocus.newWindow.show

ANS:

newWindow.focus()

Other than a checkbox, which other form element has a "checked" property? hidden select input option radio

ANS: radio

80Code function surfto(form) { var idx=form.s1.selectedIndex if(form.s1.options[idx].value != 0) location=form.s1.options[idx].value; } Choose One U2 U3 U4 Which one of the following does the above code create? Four hyperlinks Four buttons, each loading a corresponding URL when clicked Four check boxes and a button that loads the selected document when clicked A pull-down menu and a button that loads the selected document when clicked A pull-down menu with four choices that loads a selected when focus is removed

When the following code is executed in Netscape: x = new Java.lang.Double(2.05); what type of object is x? Double var ans JavaObject Number Float JavaObject

var x = 15%4; Referring to the above code, what is the value of variable "x"? 0 1 2 3 ans 4

Which one of the following objects is NOT a form element?

81

password input link select hidden

Ans :link

Sample Code

var x; x = Array(2,5,10); Referring to the above, how many elements are in the array x? 3 4 10 11 100

Ans :3

Code

Referring to the above code, what code initially places the cursor in text field "a"?

Ans: delete car.fivespeed; The above code deletes which one of the following? The car class

82The fivespeed property from the car class The fivespeed property from object car Object car Nothing Ans The fivespeed property from object car function Pass() { document.jane.elements[0].value= document.joe.elements[0].value;

}

Q Referring to the above code, what happens to the text when the user types "Hello" into the first text control and then clicks the button? Nothing, function "Pass()" contains an error. It is moved to the second text control. It is left in the first text control. It is deleted from the first text control. It is copied to the second text control.

Ans:

It is copied to the second text control.

Following are some questions whose answers are unknown..

83

84

85

86

87

88

89