JavaScript Test

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

7.26 Which of the following flowchart symbols can represent an if statement? a) diamond b) oval/circle c) rectangle d) flowline

a) diamond

9.61 The technique of developing and maintaining a large program by constructing it from small, simple pieces is called ________. a) divide and conquer b) modular programming c) multitasking d) multiprogramming

a) divide and conquer

8.58 Which of the following will not evaluate to true? a) false || false b) true || true c) false || true d) true || false

a) false II false

7.20 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.27 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

10.90 What is the value of num assuming that all 12 elements of array test are initialized to 3? ++test[ 7 ]; var num = test[ 7 ]; a) 3 b) 4 c) 8 d) 10

b) 4

6.14 Which of the following operators associates from right to left? a) == b) = c) + d) %

b) =

7.19 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

10.99 When working with data stored in arrays, it's often necessary to determine whether an array contains a value that matches a certain ________. a) search value b) value index c) sub initializer d) key value

d) key value

8.44 Which of the following is not required for counter-controlled repetition? a) final value b) initial value c) sentinel d) increment

c) sentinel

7.18 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

9.78 Which of the following is not a global function? a) parseInt b) escape c) square d) eval

c) square

9.75 Change an image's ________ attribute to change which picture it displays. a) location b) URL c) src d) source

c) src

7.24 Which of the following is not a JavaScript keyword? a) break b) delete c) sub d) for

c) sub

7.36 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

10.89 Which of the following is an illegal array initialization statement? a) var n = [ 10, 20, 30, 40, 50 ]; b) var n = new Array( 10, 20, 30, 40, 50 ); c) var n[ 10, 20, 30, 40, 50 ]; d) var n = new Array( 5 ); for ( var i = 1; i <= 5; i++ ) n[ i ] = i * 10 ;

c) var n[ 10, 20, 30, 40, 50 ];

9.81 When a function invokes a new copy of itself, it is called a ________. a) base case b) final step c) base case d) recursive call

d) recursive call

10.91 In JavaScript, all objects and arrays are passed to functions by ________. a) value b) parameters c) memory d) reference

d) reference

10.93 Pass-by- ________ is the method of passing the argument's address in memory to a function. a) value b) parameters c) memory d) reference

d) reference

8.51 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

7.33 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

10.87 Which of the following is the proper method to dynamically allocate memory to an array of 100 elements? a) var c = new c[ 100 ]; b) var c = new c( 100 ); c) var c = new Array[ 100 ]; d) var c = new Array( 100 );

d) var c = new Array( 100 );

7.32 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

7.42 What is the value of i after the following statements? i = 2; i--; i--; a) 0 b) 1 c) -2 d) -4

a) 0

8.49 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

6.13 Which of the following is not a valid JavaScript equality or relational operator? a) = b) < c) > c)!=

a) =

9.65 What is the result of writing the keyword var in a function parameter list? a) The result would be a JavaScript runtime error. b) The parameter following the keyword would have global scope. c) The parameter following the keyword would have local scope. d) The parameter following the keyword would become a static variable.

a) The result would be a JavaScript runtime error.

7.38 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

7.21 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

7.29 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

9.68 A function's ________ are also considered to be local variables. a) parameters b) static variables c) register variabless d) constant variables

a) parameters

7.16 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

7.34 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

9.64 Which of the following is a legal function call for the function definition provided below? function square( y ) { return y * y; } a) square(7+2); b) (7).square; c) square(7,2); d) square 7;

a) square(7+2);

10.97 By default, the JavaScript sort method uses ________ to sort the array passed to it. a) string comparison b) binary search c) linear search d) bubble sort

a) string comparison

10.92 Pass-by- ________ is the method of passing a copy of the argument's value to a function. a) value b) parameters c) memory d) reference

a) value

10.94 In JavaScript, numbers and boolean values are passed to functions by ________. a) value b) parameters c) memory d) reference

a) value

6.5 An alert dialog displaying the text "Welcome!" is created by calling _________. a) window.alert( "Welcome!" ); b) alert.window( "Welcome!" ); c) window( "alert = \"Welcome!\"" ); d) window( "<alert> Welcome! </alert>" );

a) window.alert( "Welcome!" );

7.30 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

6.12 What does the following expression evaluate to? ( ( 3 + ( 5 + 4 ) * 7 ) + 4 ) / 5 a) 8 b) 14 c) 17.6 d) 26.4

b) 14

7.43 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) 17

6.10 What is the result of the statement 17 % 5? a) 0 b) 2 c) 3 d) 12

b) 2

8.50 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

7.40 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

6.3 Consider the following HTML5 code. <html> <script type = "text/javascript"> <!-- <!-- document.writeln("Hello World"); --> //--> </script> </html> What would a browser capable of scripting display when executing this code? a) document.writeln("Hello World"); b) nothing c) Hello World d) <html> <script type = "text/javascript"> <!-- <!-- document.writeln("Hello World </p>"); //--> </script> </html>

b) Nothing

8.55 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

9.69 What does the following statement do? Math.floor( Math.random() * 12 ); a) This creates a random number from 0 up to and including 12. b) This creates a random number from 0 up to but not including 12. c) This creates a random number from 1 up to and including 12. d) This creates a random number from 1 up to but not including 12.

b) This creates a random number from 0 up to but not including 12.

7.39 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;

8.53 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

7.23 Which of the following is a JavaScript repetition statement? a) while...repeat b) do...while c) do...repeat d) for...do

b) do...while

7.22 Which of the following is not a JavaScript selection statement? a) if...else b) for...in c) switch d) if

b) for...in

9.67 All variables declared in function definitions are ________. a) global variables b) local variables c) static variables d) constant variables

b) local variables

9.60 The best way to develop and maintain a large program is to construct it from small, simple pieces called ________. a) scripts b) modules c) scriptlets d) objects

b) modules

6.11 Which of the following sequences does not follow the rules of operator precedence? Assume that operators are evaluated in the order listed from left to right. a) multiplication, division, addition b) parentheses, subtraction, modulus c) division, multiplication, addition d) parentheses, modulus, subtraction

b) parentheses, subtraction, modulus

9.62 Functions that are not provided as part of the JavaScript language are called ________ functions. a) add-on b) programmer-defined c) man-made d) extra

b) programmer-defined

7.35 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

9.70 The value a in the following statement is called the ________ and the value b is called the ________. face = Math.floor( a + Math.random() * b ); a) scaling factor, shifting value b) shifting value, scaling factor c) scaling value, shifting factor d) shifting factor, scaling value

b) shifting value, scaling factor

8.59 Which of the following will not evaluate to false? a) false && false b) true && true c) false && true d) true && false

b) true && true

9.73 Which of the following is used to access members (or properties) of form elements? a) * b) , c) . d) ;

c) .

6.7 Which of the following is not a valid variable name? a) Tax1 b) eightball_8 c) 12footage d) pageNumber1200

c) 12footage

7.41 What is the value of i after the following statements? i = 2; i++; a) 0 b) 2 c) 3 d) 4

c) 3

8.56 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) 5

8.54 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

6.1 In the following line the word document is a(n) ______ that resides in the computer's memory. document.writeln("Hello World"); a) attribute b) behavior c) object d) method

c) Object

7.17 ________ is an informal language that helps programmers develop algorithms. a) JavaScript b) ECMAScript c) Pseudocode d) AlgorithmCode

c) Pseudocode

10.95 What is the effect of the join statement in the following code? var theArray1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; var theArray2 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; var value = theArray1.join( " " ); a) The join method will concatenate the values of theArray2 to theArray1. b) The join method will concatenate the values of theArray1 to theArray2. c) The join method will create a string from the values in theArray1. d) The join method will create a string with the values of theArray2 concatenated to the values of theArray1.

c) The join method will create a string from the values in theArray1.

8.46 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

c) XXXXX

8.45 What should you use as a counter in counter-controlled repetition? a) c b) a sentinel c) an integer d) a num object

c) an integer

10.86 Which of the following is the proper method to access the length of the array arr? a) arr[].length b) arr[subscript].length c) arr.length d) arr(length)

c) arr.length

10.84 _________ are data structures consisting of related data items (sometimes called collections of data items). a) lvalues b) composites c) arrays d) variables

c) arrays

8.52 switch statements contain ________ labels. a) select b) if...else c) case d) choice

c) case

10.88 The first statement below ________ the array while the second statement ________ the array. var c; c = new Array( 12 ); a) declares, initializes b) initializes, declares c) declares, allocates d) allocates, declares

c) declares, allocates

9.71 The style of programming in which the user interacts with a GUI component is called ________ programming. a) object-oriented b) automatic c) event-driven d) modular

c) event-driven

8.48 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 )

7.25 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" );

9.63 The "prepackaged" functions that belong to JavaScript objects such as Math.pow and Math.round are often called ________. a) subroutines b) routines c) methods d) functions

c) methods

10.85 To refer to a particular location or element in the array, we specify the name of the array and the ________ of the particular element in the array. a) contents b) size c) position number d) type

c) position number

9.74 Nested in the audio element are two ________ specifying the locations of the audio clip in MP3 and OGG formats, respectively. a) source elements b) media elements c) preload attributes d) location elements

c) preload attributes

9.80 A function that calls itself either directly or indirectly through another function is called a ________ function. a) base case b) iterative c) recursive d) fibonacci

c) recursive

9.82 Iteration uses ________ statements and recursion uses ________ statements. a) counter-recursive, counter-iterative b) repetition, function calling c) repetition, selection d) function-calling, repetition

c) repetition, selection

6.9 Whenever a value is placed in a memory location, the value________. a) cannot be added if a value already exists b) can share a location in memory with another value c) replaces the previous value in that location d) will be assigned to another identifier if a value already exists

c) replaces the previous value in that location

10.100 What would the browser output if the following script is executed? <script type = "text/javascript"> <!-- var array = [ [ 1, 2, 3 ], [ 1, 2, 3 ] ]; for ( var i in array ) { for ( var j in array[ i ] ) document.write( array[ i ][ j ] + " " ); document.writeln("<br />"); } //--> </script> a) Nothing, the script would generate an error b) 1 2 3 c) 1 2 3 4 5 6 d) 1 2 3 1 2 3

d) 1 2 3 1 2 3

10.96 What will the browser display if the following script is executed? <script type = "text/javascript"> <!-- var theArray = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; modifyArray( theArray[ 3 ] ); document.write( theArray.join( " " ) ); function modifyArray( i ) { i = 11; } //--> </script> a) Nothing, the browser will generate an error. b) 1 2 3 4 5 6 7 8 9 c) 1 2 11 4 5 6 7 8 9 d) 1 2 3 11 5 6 7 8 9

d) 1 2 3 11 5 6 7 8 9

8.57 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

9.66 What would the function cube return, assuming it is called with the statement cube( 3 )? function cube( y ); { return y * y * y; } a) JavaScript runtime error b) 3 c) 9 d) 27

d) 27

6.8 What will the browser display if the following script is executed and the user enters 5 at both prompts? <script type = "text/javascript"> <!-- var firstNumber = window.prompt( "Enter an integer", "0" ); var secondNumber= window.prompt( "Enter an integer", "0" ); var thirdNumber; thirdNumber = firstNumber + secondNumber; document.write( thirdNumber ); //--> </script> a) nothing b) 0 c) 10 d) 55

d) 55

7.31 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 ); </script> a) Nothing; the browser would generate an error. b) 0 c) 50 d) 60

d) 60

7.37 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

9.77 Which of the following are valid names of scopes in JavaScript? a) local b) global c) variable d) Both (a) and (b)

d) Both (a) and (b)

7.28 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.

9.79 JavaScript references the ________ object for you when you call its functions, so you don't need to use it directly. a) document b) local c) scriptlevel d) Global

d) Global

6.2 In the following line, the word writeln is a(n) _________ that performs a task or action in the script. document.writeln("Hello World"); a) structure b) collection c) object d) method

d) Method

8.47 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

d) OOOOOO

10.101 What does the following code do? for ( var col = 0; col < a[ 2 ].length; ++col ) a[ 2 ][ col ] = 0; a) Sets the rows and columns to zero. b) Sets the rows to zero. c) Sets the columns to zero. d) Sets all the elements in row 2 to zero.

d) Sets all the elements in row 2 to zero.

9.76 Giving a local function variable the same name as a global variable will result in which of the following? a) JavaScript runtime error. b) Data corruption. c) The local function variable will rename itself. d) The local variable will "hide" the global variable.

d) The local variable will "hide" the global variable.

6.6 Consider the following script. What is wrong with the following code? <script type = "text/javascript"> var firstNumber; thirdNumber; firstNumber = window.prompt("Enter an integer", "0"); secondNumber = window.prompt("Enter an integer", "0"); thirdNumber = firstNumber + secondNumber; </script> a) thirdNumber in line 7 must be in quotes. b) The words Enter an integer in line 6 should not be in quotes. c) The word thirdnumber in line 3 should have a comma after it. d) The word var must be placed before thirdNumber in line 3.

d) The word var must be placed before thirdNumber in line 3.

7.15 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

10.98 The sort method can be given a function to use for the comparisons it makes, called a(n) ________ function. a) isLessThan b) compare c) compareTo d) comparator

d) comparator

6.4 Which of the following statements would correctly print out the sentence "Hello World" in blue? a) document.write( "<p style = \"color: blue\"); document.write( "Hello World >"); b) document.write( "<p> style = \"color: blue\" Hello World </p>); c) document.write( "<p style = \"color: blue\" Hello World + "</p>"); d) document.write( "<p style = \"color: blue\">"); document.write( "Hello World </p>");

d) document.write( "<p style = \"color: blue\">"); document.write( "Hello World </p>");

9.72 If the HTML5 form game has a text field named point in it, what is the proper way to set the text associated with point to 10? a) game.point = "10" b) game.point.text = "10" c) game.point.caption = "10" d) game.point.value = "10"

d) game.point.value = "10"

9.83 When does a recursive program go into infinite recursion? a) if the loop-continuation test never becomes false b) if the recursion test never becomes false c) if the loop-continuation test never becomes true d) if the recursion step does not converge on the base case

d) if the recursion step does not converge on the base case


Kaugnay na mga set ng pag-aaral

MGMT 340: Pearson Quiz Questions (EXAM 1 PREP)

View Set

EXAM 3: Urinary System & Electrolyte Balance

View Set

Brunner & Suddarth's Textbook of Medical-Surgical Nursing

View Set

Prueba Escrita Leccion 5 VHL Answers

View Set