Chapter 7: JavaScript: Control Statements I

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

1/28

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.

29 Terms

1
New cards

7.1 A procedure for solving a problem in terms of the actions to be executed and the order in which these actions are to be executed is called ________.

a) program control

b) a program structure

c) a control structure

d) an algorithm

d) an algorithm

2
New cards

7.2 Specifying the order in which programming statements are to be executed is called ________.

a) program control

b) a program structure

c) a control structure

d) an algorithm

a) program control

3
New cards

7.3 ________ is an informal language that helps programmers develop algorithms.

a) JavaScript

b) ECMAScript

c) Pseudocode

d) AlgorithmCode

c) Pseudocode

4
New cards

7.4 A program in which all statements are executed one after the other in the order in which they are written exhibits ________.

a) transfer of control

b) algorithms

c) sequential execution

d) direct execution

c) sequential execution

5
New cards

7.5 The word sequence in the term sequence structure refers to the sequence of ________.

a) bits in a JavaScript instruction

b) JavaScript instructions in a script

c) scripts in an HTML file

d) HTML files in a Web site

b) JavaScript instructions in a script

6
New cards

7.6 Research determined that all programs could be written in terms of only three control structures. Which of the following is not one of the three control structures?

a) goto-less structure

b) sequence structure

c) selection structure

d) repetition structure

a) goto-less structure

7
New cards

7.7 Which of the following flowchart symbols indicates that a decision is to be made?

a) diamond

b) oval/circle

c) rectangle

d) flowline

a) diamond

8
New cards

7.8 Which of the following is not a JavaScript selection statement?

a) if...else

b) for...in

c) switch

d) if

b) for...in

9
New cards

7.9 Which of the following is a JavaScript repetition statement?

a) while...repeat

b) do...while

c) do...repeat

d) for...do

b) do...while

10
New cards

7.10 Which of the following is not a JavaScript keyword?

a) break

b) delete

c) sub

d) for

c) sub

11
New cards

7.11 Which of the following statements is correct?

a) If ( studentGrade >= 60 )

document.writeln( "Passed" );

b) if ( studentGrade >= 60 );

document.writeln( "Passed" );

c) if ( studentGrade >= 60 )

document.write( "Passed" );

d) If ( studentGrade >= 60 );

document.write( "Passed" );

c) if ( studentGrade >= 60 )

document.write( "Passed" );

12
New cards

7.12 Which of the following flowchart symbols can represent an if statement?

a) diamond

b) oval/circle

c) rectangle

d) flowline

a) diamond

13
New cards

7.13 What would the browser display if the following code were executed in a script?

var x = 11;

var y = 14;

if ( x > 13 )

if ( y > 13 )

document.writeln( "x and y are > 13" );

else

document.writeln( "x is <= 13" );

a) nothing

b) 11

c) x and y are > 13

d) x is <= 13

a) nothing

14
New cards

7.14 What would the browser display if the following code were executed in a script?

var grade = 59;

if ( grade >= 60 )

document.writeln( "Passed." );

else

document.write( "Failed. " );

document.writeln( "You must take this course again." );

a) Passed.

b) Failed.

c) You must take this course again.

d) Failed. You must take this course again.

d) Failed. You must take this course again.

15
New cards

7.15 What would the browser display if the following code were executed in a script?

var product = 0;

while ( product <= 25 );

product = 2 + product;

a) nothing, the script would result in an inifite-loop error

b) 0

c) 25

d) 26

a) nothing, the script would result in an inifite-loop error

16
New cards

7.16 What would the browser display if the following code were executed in a script?

var product = 0;

while (product >= 25)

product = 2 + product;

document.writeln( product );

a) nothing, the script would result in an error

b) 0

c) 24

d) 26

b) 0

17
New cards

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

<script type = "text/javascript">
var count = 0;
var total = 0;
while ( count <= 5 )
{
total = total + 10;
count = count + 1;
}
document.write( total )

a) Nothing; the browser would generate an error.

b) 0

c) 50

d) 60

d) 60

18
New cards

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

<script type = "text/javascript">
var count = 5;
var total = 0;
while ( count > -1 )
{
total = total - 10;
count = count - 1;
}
document.write( total );
</script>

a) Nothing; the browser would generate an error.

b) 0

c) -50

d) -60

d) -60

19
New cards

7.19 If the string passed to parseInt contains a floating-point numeric value, parseInt will ________.

a) return NaN

b) return 0

c) round the value to the nearest tenth

d) truncate the floating-point part to be left with an integer value

d) truncate the floating-point part to be left with an integer value

20
New cards

7.20 If the string passed to parseInt contains text characters, parseInt will ________.

a) return NaN

b) return 0

c) return the sum of the characters' ASCII values

d) truncate the text entries

a) return NaN

21
New cards

7.21 What type of loop is shown in the script below?

<script type = "text/javascript">
var gradeValue = 0,
total = 0,
grade = 0;

while ( gradeValue != - 1 )
{
total = total + gradeValue;
grade = window.prompt( "Enter Integer Grade, -1 to Quit:" , "0" );
gradeValue = parseInt( grade );
}
</script>

a) counter controlled

b) sentinel controlled

c) algorithm controlled

d) stepwise controlled

b) sentinel controlled

22
New cards

7.22 The word top in the term top-down stepwise refinement refers to which of the following?

a) the first statement that appears in the script

b) the first statement that appears in the algorithm

c) the single statement that completely represents the script

d) the entire algorithm

c) the single statement that completely represents the script

23
New cards

7.23 What output will the following script produce?

var i = 0;

var j = 3;

var counter = 0;

while ( i < 5 )

{

if (i != j)

counter = counter + i;

i = i + 1

}

document.write( counter );

a) 9

b) 14

c) 3

d) 7

d) 7

24
New cards

7.24 What type of loop should be used in a script that processes test results for 150 students?

a) counter controlled

b) sentinel controlled

c) algorithm controlled

d) stepwise controlled

a) counter controlled

25
New cards

7.25 Which of the following is the correct abbreviation for the statement a = a * 7; ?

a) a =* 7;

b) a *= 7;

c) 7 =* a;

d) 7 *= a;

b) a *= 7;

26
New cards

7.26 If the initial value of a is 15, what new value is assigned to a in the expression a %= 4?

a) 2

b) 3

c) 4

d) 5

b) 3

27
New cards

7.27 What is the value of i after the following statements?

i = 2;

i++;

a) 0

b) 2

c) 3

d) 4

c) 3

28
New cards

7.28 What is the value of i after the following statements?

i = 2;

i--;

i--;

a) 0

b) 1

c) -2

d) -4

a) 0

29
New cards

7.29 What is the output of the following script?

i = 16;

document.write( ++i );

a) 16

b) 17

c) 15

d) Nothing; the browser would generate an error.

b