McGraw-Hill OnlineMcGraw-Hill Higher EducationLearning Center
Student Center | Instructor Center | Information Center | Home
Sample Code
Multiple Choice Quiz
True or False
E-Lectures
Feedback
Help Center


Programming the Web Using XHTML and JavaScript
Larry Randles Lagerstrom

Loops and Arrays

Multiple Choice Quiz



1

What does the following improperly indented while loop display? (hint: rewrite it with proper indentation)
var k = 0
while (k < 5)
alert(k)
k++
A)0, 1, 2, 3, 4
B)1, 2, 3, 4, 5
C)0, 1, 2, 3, 4, 5
D)0, 0, 0, 0, 0, 0, 0, … forever
2

Which is NOT a loop in JavaScript?
A)do-while
B)for
C)while
D)while-do
3

Which is NOT a loop in JavaScript?
A)do-3
B)threepeat
C)repeat
D)none of the above are JavaScript loops
4

Which statement creates an array that can hold 7 elements?
A)var a = new Array[7]
B)var a = new Array(6)
C)var a = new array(6)
D)var a = new Array(7)
5

Suppose a web page includes one form named f with three text fields. Which statement will display what the user has entered in the first one?
A)alert(document.f.elements[1].value)
B)alert(document.f.elements[0])
C)alert(document.f.textbox[0].value)
D)alert(document.forms[1].elements[1].value)
6

Suppose a web page includes two forms named f1 and f2 with three text fields. Which statement will display what the user has entered in the second text field in the first form?
A)alert(document.f1.elements[1].value)
B)alert(document.forms[0].elements[1].value)
C)alert(document.forms[1].elements[2].value)
D)both A and B
7

What will be displayed by the following?
var k = 1, answer = "0"
while (k <= 3){
answer = answer + " " + k
k++
}
alert(answer)
A)0 1 2 3 4
B)0 1 2 3
C)10
D)6
8

What will be displayed by the following?
var k = 1, answer = 0
while (k <= 3){
answer = answer + k
k++
}
alert(answer)
A)0 1 2 3 4
B)0 1 2 3
C)10
D)6




McGraw-Hill/Irwin