CSIS 228

Ace your homework & exams now with Quizwiz!

Ch2 Suppose you want to run the calcTotal() function each time the user of a web form changes an input control with the id "quantity." What belongs in the blank in this JavaScript statement? a)onchange.value b)onchange = calcTotal c)onchange.calcTotal d)value = calcTotal

b)onchange = calcTotal

Ch4 Suppose you see the following lists of functions in the call stack window of your browser's debugger as you are examining your JavaScript code. What does this call stack information indicate? siftFlour prepareBatter bakeCupcakes a)The bakeCupcakes function has called both the prepareBatter and siftFlour functions. b)The bakeCupcakes function contains an error. c)The siftFlour function is active at the current breakpoint. d)The prepareBatter function calls the bakeCupcakes function.

c)The siftFlour function is active at the current breakpoint.

Ch3 Which of the following statements creates an array of elements of the integer data type with a length property value of 5? a)let unitsSold = ["77", "28", "34", "52", "45"]; b)unitsSold.length = [5]; c)let unitsSold = [35, 88, 29, 37, 33]; d)let unitsSold[5] = 63;

c)let unitsSold = [35, 88, 29, 37, 33];

Ch4 A load-time error _____. a)is represented by the browser console message: Uncaught ReferenceError: amt is not defined. b)occurs when a browser attempts to run a JavaScript statement c)will result from a syntax mistake such as a misspelled JavaScript keyword d)may be caused by a JavaScript function that uses an undeclared variable

c)will result from a syntax mistake such as a misspelled JavaScript keyword

Ch3 Imagine you want to write JavaScript code to display a customized message depending on the value of the dessert variable. Which series of words belongs in the blanks (one word per blank)? _____ (dessert) { _____ "Ice cream": alert("We all scream for ice cream!"); break; _____ "Apple pie": alert("Full of baked cinnamon-sweet fruit!"); break; _____ "Brownies": alert("A rich and gooey chocolate treat!"); break; _____ alert(dessert + " is always an excellent choice!"); } a)if, else if, else if, else if, else b)switch, dessert, dessert, dessert, default c)case, if, if, if, else d)switch, case, case, case, default

d)switch, case, case, case, default

Ch2 An important distinction between methods and functions is that _____. a)functions can be called only once in a program b)methods are actions associated with an object c)functions are attributes associated with an object d)methods can be called only once in a program

b)methods are actions associated with an object

Ch4 If you wish to observe how a single expression or variable value changes as your JavaScript program executes, the most efficient approach is to _____. a)open the debugger's Scope window and select it within this window b)display the call stack within the debugger, then search for instances of it within the results c)use the debugger to add breakpoints at each spot where you suspect it changes, then step through execution d)copy one instance of it to the Clipboard, then paste it into the debugger's Watch window

d)copy one instance of it to the Clipboard, then paste it into the debugger's Watch window

Ch3 Suppose you want to write a command block that counts by threes from 3 to 99 and displays the results. What should you place in the blank? _____ document.write(i + "<br>"); } a)while (i < 100) { b)do (let i = 3; i < 100; i += 3) { c)for (let i = 0; i < 99; i += 3) { d)for (let i = 3; i < 100; i += 3) {

d)for (let i = 3; i < 100; i += 3) {

ch1 It is the best practice to place all JavaScript scripts at the beginning of an HTML file so that they will not be run until after the Document Object Model has been created. true false

false

ch1 JavaScript programmers must include code to respond to the complete set of trigger events in each script because all events occur with all devices that run browser applications. a)true b)false

false

Ch.5 What does the following JavaScript statement do? let timeID = window.setTimeout(logOut, 60000); a) runs the logOut function after a 1-minute delay b) sets the timeout property of the logOut object to 60,000 seconds c) runs the logOut function after 1 minute, then repeats it every 1 minute d) stops execution of the logOut timed function after 1 minute

a) runs the logOut function after a 1-minute delay

Ch2 When the JavaScript expression (10 + 10) + 2 * 5 is evaluated, the addition within the parentheses is performed first, then the multiplication operation, then the remaining addition operation. a)True b)False

a)True

Ch3 The following JavaScript code will display the message "You can vote!" if the age variable's value is 40, but will display "When you are 18, you can vote!" if the age variable's value is 4. if (age >= 18) { window.alert("You can vote!"); } else { window.alert("When you are 18, you can vote!"); } a)True b)False

a)True

Ch3 Usually, when a programmer needs to iterate over an array in JavaScript, an array method will be a faster and more compact choice than a program loop. a)True b)False

a)True

ch1 In JavaScript, _____. a) the document.write() method should be used only for large blocks of content and should be placed in a separate file, not embedded in an HTML file b)the statement document.write("Today's special: dumplings!"); can be used to display a message on a web page c)the statement document.write(True); instructs the browser to execute the following block of code within a web page d)the document.write() method should be used to display static text in a web browser when a document is first rendered

b)the statement document.write("Today's special: dumplings!"); can be used to display a message on a web page

Ch1 In the context of programming web applications, a user typing in a form field with a keyboard, the occurrence of an error as a browser attempts to load a page, and a user touching a webpage element on a mobile phone screen are all examples of events. true false

true

Ch4 Imagine that you are writing a JavaScript program to display the line items, before-tax discount, sales taxes, and total price for a user's order. An error in this program is classified as a logic error when it _____. a)involves an illegal mathematical operation during the total price calculation b)prevents the program from being successfully loaded by the browser c)halts program execution before all page elements are displayed by the browser d)causes the discount to be applied after the taxes are added to the price, making the total price incorrect

d)causes the discount to be applied after the taxes are added to the price, making the total price incorrect

Ch3 Which JavaScript statement will create an array using an array literal? a)new Array = (sherbets, ["orange", "lime", "lemon", "raspberry"]); b)arr sherbets = {"orange", "lime", "lemon", "raspberry"}; c)let sherbets = {"orange", "lime", "lemon", "raspberry"}; d)let sherbets = ["orange", "lime", "lemon", "raspberry"];

d)let sherbets = ["orange", "lime", "lemon", "raspberry"];

Ch2 Suppose you have written the following function. function salesTax(price, rate) { let tax = price * rate; return tax; { How can you call the function, passing in values of 9% for the sales tax rate and $20 for the price? a)tax = 20 * 0.09; b)salesTax(0.09, 20); c)function salesTax(20, 0.09); d)salesTax(20, 0.09);

d)salesTax(20, 0.09);

ch1 When naming and using variables in JavaScript, you should remember that _____. a)the interpreter will still recognize the variable called shelter if you capitalize it as SHELTER b)Shelter and HomelessPet are appropriate for object names c)you cannot assign identifiers that include capital letters, such as homelessPet, to variables d)shelter and homelesspet are appropriate names for objects

d)shelter and homelesspet are appropriate names for objects

ch1 When a variable is declared and initialized with the statement var velocity = 32;, this means that _____. a) the variable velocity was declared and initialized without using an assignment operator b) the variable velocity can only hold a numerical value, not a text string c) it has a somewhat different scope than if it were declared using the let keyword d) it stores a constant value that cannot be changed

it has a somewhat different scope than if it were declared using the let keyword (this might be wrong, but a us NOT the answer)

Ch3 If you are writing a while loop that increases the counter variable i by 1, and want the loop to stop after six iterations, you should _____. a)initialize i with a value of 1 and use i >= 1 as the conditional expression b)initialize i with a value of 0 and use i <= 5 as the conditional expression c)initialize i with a value of 0 and use i < 7 as the conditional expression d)initialize i with a value of 1 and use i <= 5 as the conditional expression

b)initialize i with a value of 0 and use i <= 5 as the conditional expression

Ch4 Imagine that you are trying to locate some logic errors in a JavaScript program using your browser console's debugging tools. You can use the "_____" button to trace a function step by step, or the "_____" button to run a function without evaluating it in detail. a)step out, step over b)step into, step over c)step over, step into d)step into, step out

b)step into, step over

Ch2 How would you write a named function that displays a sentence with two parameters values inserted in an alert box? a)function (size, topping) { window.alert("Your free " + size + " pizza topped with " + topping " is on its way!"); } b)function pizzaConf(size, topping) { window.alert("Your free " + size + " pizza topped with " + topping " is on its way!"); } c)function (size, topping) { return size; } d)pizzaConf function(size, topping) { window.alert("Your free " + size + " pizza topped with " + topping " is on its way!"); }

b)function pizzaConf(size, topping) { window.alert("Your free " + size + " pizza topped with " + topping " is on its way!"); }

Ch2 After the following JavaScript code executes, the message "Get back to work!" will display. let holiday = 0(holiday) ? window.alert("Enjoy your day off!") :window.alert("Get back to work!"); a) True b) False

a) True

ch1 A(n) _____ transforms a set of instructions written in a programming language into machine code, which can be understood by a computer. a) compiler b) scripter c)browser d)interpreter

a) compiler

ch1 What is an API? a)a set of procedures that access an application b)a system consisting of a client and a server c)a scripting programming language d)a system for exchanging data on the web

a)a set of procedures that access an application

Ch4 When you discover that several variables are assuming inappropriate values at some point in your long, complex JavaScript program but don't know where or how this is happening, you should _____. a)open your debugger's Scope window to watch how the values change as the program executes b)examine the syntax for load-time and runtime errors c)insert alerts that will display the variables' values at various points in the program using the window.alert() method d)use the Watch buttons in your debugger to pause and resume program execution at breakpoints

a)open your debugger's Scope window to watch how the values change as the program executes

CH5 The JavaScript navigator.platform property should be used to determine a user's browser application's primary language. a) True b) False

b) false

Ch2 When the Google Chrome browser console reports the location of an error as js40.js:30, this means it is found on line 40 of the JavaScript file that prompted the error. a)True b)False

b)False

Ch3 The following JavaScript code correctly nests conditional statements without syntax errors.if (isBirthday === true) { if (age === 20) { window.alert("You have been alive for exactly two decades."); else if (age === 30) { window.alert("You have been alive for exactly three decades."); else { window.alert("A new year of your life begins today.");} else { window.alert("Today is your un-birthday.");} a)True b)False

b)False

Ch4 When you anticipate that a user error may occur during the execution of a set of JavaScript statements, you can handle potential errors by placing them within a catch command block. a)True b)False

b)False

Ch4 In a JavaScript program, which of the following will cause a runtime error? a)omitting a closing curly brace from the end of a function b)attempting to use a variable defined within one function to perform calculations in a different function c)attempting to use a variable with global scope to perform calculations within a function d)placing statements that must be executed in the wrong order

b)attempting to use a variable defined within one function to perform calculations in a different function

Ch4 A breakpoint _____. a)triggers the browser console to write messages about the state of the program to its log b)can be inserted by clicking a source code line number within the browser console c)can be added to the beginning of a JavaScript program to run the interpreter in strict mode d)is inserted by adding the break keyword to end of a line of JavaScript code

b)can be inserted by clicking a source code line number within the browser console

Ch3 Suppose you would like to reference the third image from an HTML document, which has the tag <img src="smileyface.png" id="BeHappy" alt="Big smile">, in your JavaScript code. Which expression should you use? a)document.images["Big smile"] b)document.images["BeHappy"] c)document.images.smileyface d)document.images[3]

b)document.images["BeHappy"]

Ch2 JavaScript primitive data types _____. a)classify JavaScript as a statically typed language b)include Booleans, which have a logical value of either true or false c)include null, the data type of a variable that has been declared but not initialized d)must be used with the object data type to specify the categories of information variables contain

b)include Booleans, which have a logical value of either true or false

ch1 You can use the addition operator (+) in several ways in JavaScript. However, you CANNOT use the addition operator to _____. a) combine the text string "Your score is: " with the integer 20 in displayed text b) combine the text string "Good morning, " with the value of firstName c) perform arithmetic operations using the names of variables with integer values d) add the integer 10 and the string "10" to return the integer 20

d) add the integer 10 and the string "10" to return the integer 20

ch1 Which element of the JavaScript expression document.write("<p>The current time in " + cityName + " is " + currentTime + ".</p>"); is a literal? a)write b)cityName c)document d)"<p>The current time in "

d)"<p>The current time in "

Ch2 Which JavaScript expressions both return the value 3? a)2**1 and 5-2 b)300/100 and 5**-2 c)2+1 and 12%4 d)23%10 and 36/12

d)23%10 and 36/12

Ch4 Which statement about how JavaScript compares with other common programming languages is true? a)JavaScript requires stricter adherence to syntax than C++. b)Whereas using C++ requires strict adherence to syntax, Java and JavaScript are more forgiving. c)JavaScript, Java, and C++ are all similar in their degree of syntax strictness. d)Java and C++ will reject code that departs from syntax rules, whereas the JavaScript interpreter will run code even with errors.

d)Java and C++ will reject code that departs from syntax rules, whereas the JavaScript interpreter will run code even with errors.

Ch3 Which statement about counter variables used in program loops is correct? a)The counter variable should be initialized as the first statement within the loop command block that will be repeatedly executed. b)It is best practice for counter variables to have global scope. c)It is common for programmers to use variables named counter1, counter2, and counter3 for program loops. d)The value of the counter variable changes with each iteration of the loop.

d)The value of the counter variable changes with each iteration of the loop.

Ch2 The JavaScript statement let pizzaPrice = rewardsCustomer ? 20.0 : 18.5; _____. a)assigns the value 18.5 to the variable pizzaPrice if the value of rewardsCustomer is undefined b)assigns the value of rewardsCustomer to the variable pizzaPrice because 20.0 is greater than 18.5 c)assigns the value of rewardsCustomer to the variable pizzaPrice if it is between 20.0 and 18.5 d)assigns the value 18.5 to the variable pizzaPrice if the value of rewardsCustomer is true

d)assigns the value 18.5 to the variable pizzaPrice if the value of rewardsCustomer is true


Related study sets

Cost and Managerial Accounting Unit 5: Module 10

View Set

MGT 340 Final (cumulative, exams 1 - 4 in order)

View Set

ATI Nursing Fundamentals - Chapter 16-25: Nursing Throughout the Lifespan

View Set

The internal structure of the earth

View Set

Becoming Muhammad Ali by James Patterson and Kwame Alexander

View Set