Js
Js
Quiz Answers
1.b. Although some of the syntax is similar, JavaScript got its Java-based name mostly
because of a marketing relationship.
2.a. JavaScript programs execute on the web browser. (There is actually a server-side
version of JavaScript, but that's another story.)
3.c. JavaScript is supported by both Netscape and Internet Explorer, although the
implementations are not identical.
Quiz Questions
Test your knowledge of JavaScript by answering the following questions:
1.What software do you use to create and edit JavaScript programs?
a. A browser
b. A text editor
c. A pencil and a piece of paper
2.What are variables used for in JavaScript programs?
a. Storing numbers, dates, or other values
b. Varying randomly
c. Causing high school algebra flashbacks
3.What should appear at the very end of a JavaScript script embedded in an HTML
file?
a. The <script LANGUAGE="JavaScript"> tag
b. The </script> tag
c. The END statement
Quiz Answers
1.b. Any text editor can be used to create scripts. You can also use a word processor if
you're careful to save the document as a text file with the .html or .htm extension.
2.a. Variables are used to store numbers, dates, or other values.
3.b. Your script should end with the </script> tag.
Quiz Questions
Test your knowledge of JavaScript by answering the following questions:
1.A script that executes when the user clicks the mouse button is an example of what?
a. An object
b. An event handler
c. An impossibility
2.Which of the following are capabilities of functions in JavaScript?
a. Accept parameters
b. Return a value
c. Both of the above
3.Which of the following is executed first by a browser?
a. A script in the <head> section
b. A script in the <body> section
c. An event handler for a button
Quiz Answers
1.b. A script that executes when the user clicks the mouse button is an event handler.
2.c. Functions can accept both parameters and return values.
3.a. Scripts defined in the <head> section of an HTML document are executed first by the
browser.
Quiz Questions
Test your knowledge of JavaScript by answering the following questions:
1.Which of the following objects can be used to load a new URL into the browser window?
a. document.url
b. window.location
c. window.url
2.Which object contains the alert() method?
a. window
b. document
c. location
3.Which of the following DOM levels describes the objects described in this hour?
a. DOM level 0
b. DOM level 1
c. DOM level 2
Quiz Answers
1.b. The window.location object can be used to send the browser to a new URL.
2.a. The window object contains the alert() method.
3.a. The objects described in this hour fall under the informal DOM level 0
specification
Quiz Questions
Test your knowledge of JavaScript by answering the following questions:
1.Which of the following is not a valid JavaScript variable name?
a. 2names
b. first_and_last_names
c. FirstAndLast
2.If the statement var fig=2 appears in a function, which type of variable does it declare?
a. A global variable
b. A local variable
c. A constant variable
3.If the string test contains the value The eagle has landed., what would be the value
of test.length?
a. 4
b. 21
c. The
4.Using the same example string, which of these statements would return the word eagle?
a. test.substring(4,9)
b. test.substring(5,9)
c. test.substring("eagle")
5.What will be the result of the JavaScript expression 31 + "angry polar bears"?
a. An error message
b. 32
c. "31 angry polar bears"
Quiz Answers
1.a. 2names is an invalid JavaScript variable name because it begins with a number. The
others are valid, although they're probably not ideal choices for names.
2.b. Because the variable is declared in a function, it is a local variable. The var keyword
ensures that a local variable is created.
3.b. The length of the string is 21 characters.
4.a. The correct statement is test.substring(4,9). Remember that the indexes start with
0, and that the second index is noninclusive.
5.c. JavaScript converts the whole expression to the string "31 angry polar bears". (No
offense to polar bears, who are seldom angry and rarely seen in groups this large.)
Quiz Questions
Test your knowledge of JavaScript by answering the following questions:
1.What JavaScript keyword is used to create an instance of an object?
a. object
b. new
c. instance
2.What is the meaning of the this keyword in JavaScript?
a. The current object.
b. The current script.
c. It has no meaning.
Quiz Questions
Test your knowledge of JavaScript libraries and built-in functions by answering the following
questions.
1.Which of the following objects cannot be used with the new keyword?
a. Date
b. Math
c. String
Quiz Questions
Test your knowledge of JavaScript events by answering the following questions.
1.Which of the following is the correct event handler to detect a mouse click on a link?
a. onMouseUp
b. onLink
c. onClick
2.When does the onLoad event handler for the <body> tag execute?
a. When an image is finished loading
b. When the entire page is finished loading
c. When the user attempts to load another page
3.Which of the following event object properties indicates which key was pressed for an
onKeyPress event in Internet Explorer?
a. event.which
b. event.keyCode
c. event.onKeyPress
Quiz Answers
1.c. The event handler for a mouse click is onClick
2.b. The <body> tag's onLoad handler executes when the page and all its images are finished
loading.
3.b. In Internet Explorer, the event.keyCode property stores the character code for each
keypress.
Quiz Questions
Test your knowledge of the DOM's window features by answering the following questions.
1.Which of the following methods displays a dialog box with OK and Cancel buttons,
and waits for a response?
a. window.alert
b. window.confirm
c. window.prompt
2.What does the window.setTimeout method do?
a. Executes a JavaScript statement after a delay
b. Locks up the browser for the specified amount of time
c. Sets the amount of time before the browser exits automatically
3.You're working with a document that contains three frames with the names first,
second, and third. If a script in the second frame needs to refer to the first frame,
what is the correct syntax?
a. window.first
b. parent.first
c. frames.first
Quiz Answers
1.b. The window.confirm method displays a dialog box with OK and Cancel buttons.
2.a. The window.setTimeout method executes a JavaScript statement after a delay.
3.b. The script in the second frame would use parent.first to refer to the first frame.