CS 290W Exam 1 Key

Fall 1999

Purdue University

 

Answers are in RED.

Questions 1-22 and 28-45 are worth 2 points each. Questions 23-27 are worth 4 points each.

 

JavaScript

 

  1. Assuming you want to declare an integer variable named "incr" and initialize it to zero in JavaScript, you could do it this way:

(a) int incr = 0;

(b) var incr = 0;

(c) integer incr = 0;

(d) "incr" = 0;

 

  1. Character strings can be enclosed in either single quotes or double quotes.

(a) true

(b) false

 

  1. Where do JavaScript function definitions usually appear in the HTML file?

(a) HEAD

(b) HREF

(c) FORM

(d) TITLE

 

  1. Where can JavaScript code appear in an HTML file?

(a) FORM only

(b) BODY only

(c) HEAD only

(d) HEAD and BODY

 

  1. Given the script tags below, Netscape 4.0 executes code for which version of JavaScript?

(a) <SCRIPT LANGUAGE="JavaScript">

(b) <SCRIPT LANGUAGE="JavaScript1.1">

(c) <SCRIPT LANGUAGE="JavaScript1.2">

(d) all of the above

 

  1. You have created a JavaScript function named checkit that examines several values in a form. In the INPUT tag...<INPUT TYPE="button" ... onClick="checkit(__________)"> ...what goes in the blank?

(a) this

(b) this.form

(c) this.button

(d) this.form.firstname.value

 

  1. You have created a JavaScript function named validate that examines several values in a form and returns true if the form is to be submitted or false otherwise. In the FORM tag...

        <FORM ... onSubmit="return(validate(__________))">...what goes in the blank?

(a) this

(b) this.form

(c) this.button

(d) this.form.firstname.value

 

  1. What is the difference between the onBlur and onChange event handlers?

(a) onBlur may only be called if there is also an onFocus event handler. onChange may be called

      even if there is no onFocus event handler.

(b) onChange is called whenever an element loses focus. onBlur is called whenever an element

      that has been changed loses focus.

(c) onBlur is called whenever an element loses focus. onChange is called whenever an element that has been changed loses focus.

(d) Trick Question: They are equivalent.

 

  1. Which statement below will always submit a form's content, even if the user presses the Confirm box "Cancel" button?

(a) confirm('Are you sure?')

(b) onSubmit="confirm('Are you sure?')"

(c) onSubmit="return(confirm('Are you sure?'))"

(d) onSubmit=""

 

  1. Regarding the open method:

(a)     it is a method available for the document and window object

(b)     it is a method available for only the window object

(c)     if you don’t specify which object you’d like to open, an error results

(d)     if you don’t specify which object you’d like to open, it defaults to the window object

 

  1. The plugin array is a property of which object

(a)     the window object

(b)     the document object

(c)     the navigator object

(d)     the form object

 

  1. Which of the following will open a new window (not the current one being viewed) and display the color.html file?

(a) location="color.html";

(b) setTimeout('location = "color.html"', 3000);

(c) setInterval('location = "color.html"', 3000);

(d)     window.open("color.html");

 

  1. JavaScript is an interpreted language, not a compiled language.

(a) true

(b) false

 

  1. JavaScript utilizes static binding and not dynamic binding

(a) true

(b) false

 

  1. Regarding your binding answer above, how does this affect you as a programmer?

(a)     you don’t have to worry about errors so much, because the compiler will tell you about errors before your user  uses the code

(b)     you don’t have to worry about errors so much, because the interpreter will tell you about errors before your users uses the code

(c)     you must worry, because the compiler doesn’t tell you about errors until the user uses the code

(d)     you must worry, because the interpreter doesn’t tell you about errors until the user uses the code

 

  1. Why use the “new Array()” construct?

(a)     to utilize built-in properties and methods of the array object

(b)     you have no choice; this is the only way to create arrays in JavaScript

(c)     this is not possible in JavaScript as the array does not have a  “new” constructor

(d)     none of the above are correct

 

Review the code below, then answer the following three questions:

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- Hide script from old browsers

function increase (number)

 {

   return (number + 1);

 }

// end script hiding from old browsers -->

</SCRIPT>

</HEAD>

<BODY>

<SCRIPT LANGUAGE="JavaScript">

   document.write("The function returned ",

   increase(7), ".");

</SCRIPT>

<P> That is all.... <P>

</BODY>

 

  1. Select the best answer:

(a) This is bad code, because it is illegal to use more than one set of script tags in one HTML file.

(b) This is bad code, because you cannot make a function call this way

(c) This is good code and is a commonly used way to define a function and then make a call to that function.

(d) none of the above are correct

 

  1. This code opens a new window and writes to that document:

(a) The function returned 8.

(b) 8.

(c) The function returned 8

(d) It does not open up a new window. It writes the result to the current document.

 

  1. The script tags are case sensitive, so must be capitalized.

(a) true

(b) false

 

  1. The second <FORM> tag in a document has a NAME attribute of "myForm", you can refer to the form as:

(a) document.forms[1]

(b) document.forms["myForm"]

(c) document.myForm

(d) two of the above are correct

(e) all of the above

 

  1. The plug-in array is a property of the:

(a) document object

(b) navigator object

(c) form object

(d) JavaScript object

 

  1. The navigator object is also known as the browser object.

(a) true

(b) false

___________________________________________

 

Review the code below, then answer the questions #23 through #27. This is the DaVinci page we discussed in class last Friday where mousing over images pops up a text title for the image. Remember the diagram I drew on the board, and that will help. In addition, you may want to draw your own diagram to help see the placement of the images.

 

NOTE: EACH of the FIVE questions are FOUR points each.

 

1. <HTML><HEAD><TITLE>A Complex Rollover</TITLE>

2. <SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">

3.             <!-- Hide script from old browsers

4.             if (document.images) {

5.                             flyText = new Image

6.                             bgText = new Image

7.                             flyText.src = "fmText.gif"

8.                             bgText.src = "bg.gif"

9.             } else {

10.                           flyText = ""                          

11.                           bgText = ""                          

12.                           document.textField = ""

13.           }

14.           // End hiding script from old browsers -->

15. </SCRIPT></HEAD>

16. <BODY BGCOLOR="#EECC99"><TABLE><TR VALIGN=TOP>

17.   <TD>

18.      <IMG SRC="leoText.gif" WIDTH=375 HEIGHT=26><BR>

19.      <A HREF="flyPage.html" onMouseover="document.textField.src=flyText.src"

20.                                                    onMouseout="document.textField.src=bgText.src">

21.      <IMG SRC="flyer.gif" WIDTH=293 HEIGHT=165 BORDER=0 VSPACE=20>

22.      </A><BR>

23.   </TD>

24.   <TD>

25.      <IMG SRC="DaVinci.jpg" WIDTH=144 HEIGHT=219><BR>

26.      <IMG SRC="bg.gif" WIDTH=208 HEIGHT=27 NAME="textField" >

27.   </TD></TR></TABLE></BODY></HTML>

 

________________________________________________

 

  1. What does line 4 do?

(a) returns boolean true if the images have been preloaded on the page

(b) retrurns boolean true if the the image arrary has been defined due to the presence of the IMG tag(s)

(c) returns boolean true if there is more than one image

(d) does not return a boolean, but returns the first image in the image array, if it exists

 

  1. What does line 5 do?

(a) sets a variable named "flyText" to hold an image where the  filename of the image is "Image"

(b) the image contains a graphic and text, and this assignment sets the text part of the image to the

      variable "flyText"

(c) "flyText" is assigned to hold a new Image object.

(d) preloads an image in a new image object

 

  1. What does line 7 do?

(a) preloads an image in a new image object

(b) creates a new image object

(c) does not preload the image

(d) both (a) and (b)

(e) both (b) and (c)

 

  1. What image is loaded in "bgText.src"?

(a) the big picture of DaVinci

(b) the text image that is DaVinci's name

(c) the background color of the page

(d) the transparent background label

 

  1. Where is the flyer image (flyer.gif...which is one of DaVinci's flying machines) loaded on the page?

(a) in the second table column, replacing the image of DaVinci (DaVinci.jpg)

(b) it is not loaded on the current page, but on the flyPage.html, provided for in the HREF tag

(c) in the first table column under the leoText.gif

(d) in the second table column under the DaVinci picture

 

 

 

<HTML><HEAD><TITLE>…</TITLE></HEAD>

<BODY>

<SCRIPT LANGUAGE=… TYPE=…SRC=“code.js”>

</SCRIPT>

<P> Here’s the rest of the page.

</BODY></HTML>

 

  1. Regarding the code above, answer the following one question.

(a) this is one method of including a Cascading Style Sheet

(b) this is one method of including a plain text page with JavaScript code

(c) it is not legal code, as all JavaScript code must be in the same file as the HTML page that

     uses it.

(d) none of the above

 

Advanced HTML

 

  1. Which of the following is true about naming (NAME=) frames?

(a) All frames must be named.

(b) Only one frame of a FRAMESET can be named.

(c) A frame is usually named only if some other frame needs to refer to it.

(d) Any frame can be named "_top".

 

Look at the code below, then answer the following three questions.

 

<HTML><HEAD><TITLE> ... </TITLE>

<STYLE>

H1 {text-align:center; letter-spacing:.5em; background:green; color:yellow; font:normal 20pt "Nueva Roman", Verdana"}

 

P {text-align:justify; text-indent:8pt; font:10pt/15pt "Roman", Lithos Regular"}

</STYLE>

</HEAD> <BODY>... </BODY> </HTML>

 

  1. The above is an example of which type of style sheet:

(a) local

(b) internal

(c) external

(d) linked

 

  1. This HTML page will be rendered by the browser in the following way:

(a) all headings of size one will be centered and have green text with a yellow background

(b) all headings on the page will be centered and have yellow text

(c) all paragraphs will be indented and justified

(d) only the first paragraph will be indented and justified 

 

  1. What happens if you want to change the style of a heading of size one to alter it from the above declaration, and you make the change in the <H1> tag of the particular heading you'd like to alter on your page.

(a) the local heading declaration will be asserted

(b) the internal heading declaration will be asserted

(c) an error will result and your page will probably be blank or not what you'd expect

(d) no style will be asserted to that heading, since  there is a declaration conflict

 

 

Look at the code below and answer the one question following the code.

 

.periwinkle { color: #6699ff }

 <STRONG CLASS="periwinkle"> This is bold, periwinkle text. </STRONG>

 

  1. The declaration and then use of  the style above is an example of which type of style sheet class?

(a) linked class

(b) one that utilizes a class that is declared for a particular tag

(c) imported class

(d) generic class

 

  1. Which browser was the first to support style sheets?

(a) Lynx

(b) Netscape

(c) Internet Explorer

(d) Mosaic

 

  1. What happens if two style sheets are linked to the same HTML document and a particular tag in the HTML document has more than one style declaration, one declaration from each style sheet?

(a) the style declaration closest to the tag will be asserted to the tag.

(b) the style declaration farthest from the tag will be asserted to the tag.

(c) an error message results.

(d) no styles will be asserted. The browsers can't handle conflicts.

 

  1. What does the following mean...? <FRAMESET COLS="85,*">

(a) There are two columns -- each of 85 pixels.

(b) The first column is 85 pixels. The second column is the remainder of the framed area.

(c) The first column is 85% and the second column is 15% of the framed area.

(d) The first column is 85 pixels. There is no second column.

 

  1. Which of the following best describes Client Side and Server Side Image Maps?

(a) With a Client Side Image Map, the browser decides what URL to request for any given click.

(b) With a Server Side Image Map, the browser decides what URL to request for any given click.

(c) Both Client and Server Side Image Maps handle CIRCLE areas in exactly the same way.

(d) Both Client and Server Side Image Maps use the ISMAP attribute.

 

  1. Which of the following is true about naming (NAME=) frames?

(a) All frames must be named.

(b) Only one frame of a FRAMESET can be named.

(c) A frame is usually named only if some other frame needs to refer to it.

(d) Any frame can be named "_top".

 

  1. Which of the following is a disadvantage of server-side image maps (as opposed to client-side image maps)?

(a) Browser cannot tell you what page is going to be requested if you click on a spot.

(b) Shapes cannot be circles.

(c) Rectangles require all four corner coordinates.

(d) Must use the <MAP> tag.

 

  1. An image map contains a circle that is completely inside a square. You want clicks on the circle to go to some place different from clicks in other parts of the square. In what order should these be listed?

(a) circle, then square

(b) square, then circle

(c) It makes no difference.

(e)     Trick Question: Image maps may NOT have one shape inside another.

 

  1. What words are used in the <IMG> tags of image maps?

(a) ISMAP is used with server-side image maps. USEMAP is used with client-side image maps.

(b) USEMAP is used with server-side image maps. ISMAP is used with client-side image maps.

(c) SSIMAP is used with server-side image maps. CSIMAP is used with client-side image maps.

(d) MAP is used with both server-side and client-side image maps.

 

  1. For a client-side image map, what container specifies all shapes, coordinates, and URLS?

(a) CSIMAP

(b) ISMAP

(c) MAP

(d) POLY

 

  1. For a client-side image map, what coordinates are needed for SHAPE=CIRCLE?

(a) center and radius

(b) center and any edgepoint

(c) any two edgepoints

(d) radius and any edgepoint

 

  1. The keywords for imagemaps are...

(a) POL, REC, CIR and DEF

(b) POLYGON, RECTANGLE, SQUARE, CIRCLE and DEFAULT

(c) SHAPE, SIZE, WIDTH, HEIGHT

(d) POLY, RECT, CIRCLE, and DEFAULT

 

  1. What is the name of the CS 290W news group?

(a) purdue.cs290w

(b) purdue.cs.cs290w

(c) purdue.class.cs.290

(d) purdue.class.cs290w