Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Test Bank for Introduction to JavaScript Programming with XML and PHP : 0133068307

Test Bank for Introduction to JavaScript


Programming with XML and PHP : 0133068307

To download the complete and accurate content document, go to:


https://testbankbell.com/download/test-bank-for-introduction-to-javascript-programmin
g-with-xml-and-php-0133068307/

Visit TestBankBell.com to get complete for all chapters


Introduction to JavaScript Programming Test Bank Chapter 5
with XML and PHP

Test Bank for Chapter 5

MULTIPLE CHOICE

1. Which of the following give the result of 6 if num = 5.423?

a. parseInt(num) b. Math.round(num)
c. Math.floor(num) d. Math.ceil(num)
ANS: D

2. Which statement allows you to skip an iteration in a loop?

a. continue b. break c. isNaN() d. any of these


ANS: A

3. Which type of loop can be nested in a for loop?

a. for b. while c. do...while d. any of these


ANS: D

4. What will be displayed after the following code snippet runs?

function itLoops()
{
var m = 0; var k = 0; var p = 0;
while (m < 3)
{
k = m;
for (p = 1; p < 6; p+=3)
{
k = k + p;
document.write(k + " ");
}
document.write("<br />");
m++;
}
}
a. 1 5 b. 0 4 c. 1 5 d. 2 6
2 6 1 5 2 6 3 7
3 7 2 6 3 7
4 8
ANS: A

© 2014 Pearson Education 1


Introduction to JavaScript Programming Test Bank Chapter 5
with XML and PHP

5. Which of the following will sum up all the integers between 1 and 10, inclusive?

a. var sum = 0; b var sum = 1; var i = 1;


for (var i = 1; i < 11; i ++) while(i
. < 11)
sum = sum + i; sum = sum + i;

c. var sum = 1; var i = 1; d var sum = 0;


while(i != 10) for . (var i = 1; i < 10; i++)
{ sum = sum + i;
i++;
sum = sum + i;
}
ANS: A

6. If teabags is an odd integer, what is the result of the following statement?

teabags = teabags % 2;

a. true b. false c. 0 d. 1

ANS: D

7. What is the value of sodapop after the following statements?

var sodapop = 47.33;


sodapop = Math.round(sodapop + 0.4);

a. true b. false c. 47 d. 48

ANS: D

Use the following for Questions 8 – 10

var num = 2; var sum = 0; var average = 0;


for (var count = 0; count < 3; count++)
{
sum = sum + num;
num++;
}
average = parseInt)sum/count);

8. What will the value of average be after the given code is executed?

a. 5 b. 9 c. 3 d. 4.78
© 2014 Pearson Education 2
Introduction to JavaScript Programming Test Bank Chapter 5
with XML and PHP

ANS: C

9. What is the value of sum at the end of the given code snippet?

a. 9 b. 5 c. 14 d. 12

ANS: A

10. What is the value of num at the end of the given code snippet?

a. 4 b. 5 c. 6 d. 2

ANS: B

11. Which correctly identifies an even integer, given a numeric variable named num?

a. if(num % 0); b if(num % 1);


.
c. if((num % 12)== 0); d if(num % 2);
.

ANS: D

12. Which of the following would be used to check if a number stored in a variable named eights is
divisible by 8?

a. if(eights/8 == 0); b. if((eights/8)!= parseInt(eights/8));


c. if(eights/8 != 0); d. if((eights/8)== parseInt(eights/8));

ANS: D

13. What are the possible results of the following statement?

var num = Math.floor(Math.random() * 4);

a. 0, 1, 2, or 3 b. 0, 1, 2, 3, or 4
c. 1, 2, 3, or 4 d. 1, 2, 3, 4, or 5

ANS: A

Use the following for Questions 14 and 15:

© 2014 Pearson Education 3


Introduction to JavaScript Programming Test Bank Chapter 5
with XML and PHP

<a href = '#' onmouseover = "document.photo.src = 'cat.jpg';


onmouseout = "document.photo.src = 'dog.jpg';">
<img src = 'dog.jpg' name = "photo" /></a>

14. Which image is displayed initially?

a. cat.jpg b. dog.jpg
c. photo d. cannot tell

ANS: B

15. To see the image of the cat, you must…

a. click the dog image b. move your mouse off the dog image
c. roll your mouse over the dog image d. the image of the cat is already displayed so
nothing needs to be done

ANS: C

16. Which of the following will create a rectangular block of symbols (#'s) with 3 rows and 4 symbols in
each row?

a. for(row = 0; row < 4; row++ b. for(row = 1; row < 4; row++


{ {
for(col = 0; col < 5; col++) for(col = 1; col < 5; col++)
document.write("#"); document.write("#<br />");
} }
c. for(row = 0; row < 4; row++ d. for(row = 1; row < 3; row++
{ {
for(col = 0; col < 3; col++) for(col = 1; col < 4; col++)
document.write("#<br />"); document.write("#");
} document.write("<br />");
}

ANS: B

TRUE/FALSE

1. True/False: The break statement allows you to skip one iteration in a loop.
ANS: F

2. True/False: The continue statement is used to skip all or part of a loop iteration and then finishes
the rest of the loop's iterations.
ANS: T

3. True/False: The following code will accurately find the average of four numbers entered by the user:
var sum = 0;
© 2014 Pearson Education 4
Test Bank for Introduction to JavaScript Programming with XML and PHP : 0133068307

Introduction to JavaScript Programming Test Bank Chapter 5


with XML and PHP

for(var count = 0; count < 4; count++)


sum = sum + parseFloat(prompt("Enter a number:");
var average = sum/count;
ANS: F

4. True/False: Desk checking is only used to check the results of summing or averaging values.
ANS: F

5. True/False: The accumulator is the variable that holds the total of a sum of values in a loop.
ANS: T

6. True/False: JavaScript events trigger actions in a browser.


ANS: T

7. True/False: The onmouseover event can only be used to swap one image for another.
ANS: F

8. True/False: A while loop cannot be nested in a do...while loop.


ANS: F

9. True/False: A for loop can be nested in a do...while loop.


ANS: T

10. True/False: Selection structures can be nested inside a loop but a loop cannot be nested in a
selection structure.
ANS: F

© 2014 Pearson Education 5

Visit TestBankBell.com to get complete for all chapters

You might also like