Chapter 8: JavaScript: Control Statements II

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/15

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

16 Terms

1
New cards

8.1 Which of the following is not required for counter-controlled repetition?

a) final value

b) initial value

c) sentinel

d) increment

c) sentinel

2
New cards

8.2 What should you use as a counter in counter-controlled repetition?

a) a floating-point number

b) a sentinel

c) an integer

d) a num object

c) an integer

3
New cards

8.3 What would the browser display if the following script were executed?

<script type = "text/javascript">
<!--
for ( var i = 0; var i < 5; var i++ )
document.write( "X" );
//-->
</script>

a) Nothing; the script would generate an error

b) XXXX

c) XXXXX

d) XXXXXX

a) Nothing; the script would generate an error

4
New cards

8.4 What would the browser display if the following script were executed?

<script type = "text/javascript">
<!--
for ( var i = 0; i < 5; i++ )
document.write( "O" );
//-->
</script>

a) Nothing; the script would generate an error

b) OOOO

c) OOOOO

d) OOOOOO

c) OOOOO

5
New cards

8.5 Which of the following is declared correctly and will not result in an error, assuming x = 2 and y = 30?

a) for ( var j = 10; j <= 80; j-- )

b) for ( var j = x, j <= y, j += 5 )

c) for ( var j = x; j <= 80 * y; j += 5 / x )

d) for ( var j = x; j <= 80 * y; j -= 5 )

c) for ( var j = x; j <= 80 * y; j += 5 / x )

6
New cards

8.6 What is the value of num after the following statement is performed?

num = 2 * Math.pow( 2, 3 );

a) 16

b) 18

c) 64

d) 8

a) 16

7
New cards

8.7 What is the value of num after the following statements are performed?

num = 2.4589;

num = num.toFixed( 2 );

a) 2

b) 2.46

c) 2.5

d) 2.45

b) 2.46

8
New cards

8.8 The ________ multiple-selection statement is used to handle decision making and can be used to replace multiple if and if...else statements.

a) do...while

b) case

c) break

d) switch

d) switch

9
New cards

8.9 switch statements contain ________ labels.

a) select

b) if...else

c) case

d) choice

c) case

10
New cards

8.10 In a switch statement, the ________ case clause is used to process exceptional conditions and is usually listed last.

a) break

b) default

c) else

d) then

b) default

11
New cards

8.11 Consider the following code selections. Assume count is initialized to 7 and num is initialized to 0.

i) ii)

do

{ while ( count < 6 )

num = count; num = count;

} while ( count < 6 )

What will the value of num be for i) and ii) respectively after the loops have been executed?

a) 0, 0

b) 0, 7

c) 7, 0

d) 7, 7

c) 7, 0

12
New cards

8.12 What would the browser display if it executed the following script?

<script type = "text/javascript">
<!--
var i = 0;

do
{
document.write( "O" );
i++;
} while ( i > 5 );

//-->
</script>

a) Nothing; the script would generate an error

b) O

c) OOOOO

d) OOOOOO

b) O

13
New cards

8.13 What would the browser display if it executed the following script?

<script type = "text/javascript">
<!--
for ( var count = 1; count <= 10; ++count )
{
if ( count == 5 )
break;
}

document.writeln( count );
//-->
</script>

a) Nothing; the script would generate an error.

b) 1

c) 5

d) 10

c

14
New cards

8.14 What would the browser display if it executed the following script?

<script type = "text/javascript">
<!--

for ( var count = 0; count < 10; ++count )
{
if ( count == 5 )
continue;
}

document.writeln( count );
//-->
</script>

a) Nothing; the script would generate an error.

b) 5

c) 9

d) 10

d) 10

15
New cards

8.15 Which of the following will not evaluate to true?

a) false || false

b) true || true

c) false || true

d) true || false

a) false || false

16
New cards

8.16 Which of the following will not evaluate to false?

a) false && false

b) true && true

c) false && true

d) true && false

b) true && true