CIS193 Chapter 2

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

Which JavaScript expressions both return the value 3?

23%10 and 36/12

How would you express the number 0.0055 in exponential notation?

5.5e-3

Which of the following would NOT be represented as a floating point number in JavaScript?

89

After the following JavaScript code executes, the value of c will be _____. let a = 8; let b = ++a;let c = b--;

9

Suppose you want to execute the calcCredit function when the element <input type="button" id="credit" value="Calculate" /> is clicked. How can you do this?

Add onclick="calcCredit()" before the />.

The JavaScript expression 36-- returns the value 34.

False

The expression a *= b assigns b the value equal to a * b.

False

The following JavaScript expression retrieves the Boolean value false when the user has selected (ticked) the box indicating he wants extra cheese, which has the id "extraCheese," on a web form for ordering pizza. document.getElementById("extraCheese").checked;

False

The only way to run a JavaScript function upon an event such as a page loading or a user clicking a page element is to enclose the function within an event handler or event listener.

False

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.

False

What change should be made to the JavaScript statement document.write("<p>Who likes the song "Twinkle, Twinkle, Little Star"?</p>"); if the intention is to display the string: Who likes the song "Twinkle, Twinkle, Little Star"?

Insert a backslash (\) before each of the double quotation marks around the song's title.

How do you use an event listener to trigger execution of an anonymous function?

Insert the entire structure of the anonymous function as the function argument for the addEventListener() method.

What is wrong with the following function to calculate the slope of a line? function slope(rise, run) {return ratio;let ratio = rise / run;}

The calculation statement was placed after the return statement.

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

True

Most browsers display error messages they generate in a console that can be opened by website developers, and developers can use this console as a helpful debugging tool.

True

The following JavaScript event listener will respond to the load event for the window object as it goes up the object hierarchy: window.addEventListener("load", function1);.

True

The use of global variables is strongly discouraged for applications managed by a team of programmers because, in comparison, the scope of local variables is well-contained and therefore more easily tracked.

True

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.

True

You can use Boolean values to allow your program to decide which code blocks to execute.

True

Which statement about variable scope is correct?

Variables declared with let are block scoped.

Which escape sequence, when added to a JavaScript string, will be interpreted as a new line?

\n

What belongs in the blank in the following JavaScript command if you want to run function1 in response to the load event of the window object? window._____("load", function1);

addEventListener

In JavaScript, a binary operator

appears in the expression distance + 37

What does this JavaScript statement do? let thiefType = (goodDeeds > 10 && victimType === "wealthy") ? "rascal" : "brigand";

assigns "rascal" to thiefType only if the value of goodDeeds is greater than 10 and victimType stores the string "wealthy"

The JavaScript statement let pizzaPrice = rewardsCustomer ? 20.0 : 18.5; _____.

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

A function included within a procedural program

can be called repeatedly to increase the code's efficiency

Which JavaScript expression can you use to retrieve the value from the web form input control with the id "numberOfParticipants"?

document.getElementById("numberOfParticipants").value

Which JavaScript method should you apply to respond to a click event that occurs within the page object with the id total during the capture phase?

document.getElementById("total").addEventListener("click", calcTotal, true);

Which built-in JavaScript function will return the integer 15 when called on the string "5 + 10"

eval(string)

What programming structure that can be called repeatedly throughout a program consists of a collection of statements that share a common purpose or calculate a value?

function

How would you write a named function that displays a sentence with two parameters values inserted in an alert box?

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

JavaScript primitive data types

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

Which statement demonstrates an appropriate method for storing data in a multi-line-length text string in JavaScript?

let message = "Pretend this is a very long" +" text string.";

An important distinction between methods and functions is that

methods are actions associated with an object

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? document.getElementById("quantity")._____;

onchange = calcTotal

When HTML and JavaScript code are written in separate files, the command document.getElementById("happy").onclick = makeIceCream; is used to

place an on-click event handler for the happy object within JavaScript code

Suppose you have written the following function. function salesTax(price, rate) {let tax = price * rate;return tax;{ How can you make it an anonymous function?

remove salesTax

The JavaScript expression discount == 10 _____.

returns true if the number 10 is stored in the variable discount

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?

salesTax(20, 0.09);

What does the JavaScript expression document.getElementById("numberOfParticipants").value = 0; do?

sets the value of the input control with the id "numberOfParticipants" to 0

In JavaScript, if the variable flower has been assigned the value "bluebell", the expression typeof(flower); will return _____.

string


Kaugnay na mga set ng pag-aaral

Neuro 1-2, Renal F&E, GU Reproductive Quiz questions

View Set

Chapter 26: Assessment of High Risk Pregnancy

View Set

Principles of Athletic Training Lab

View Set

Foundations of Behavioral Health Policy and Social Work Final Exam

View Set

Biology, Chapter 8 review questions

View Set

Chapter 10 Quality Control Operations Management 12e Stevenson

View Set

Chapter 15 - Information Technology

View Set