IST 226

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following is used in a regular expression pattern to match the beginning of a string?

*

What will futureValue contain after the for loop has been executed one time? var years = 10; var annualRate = 10; var futureValue = 1000; annualRate = annualRate / 100; for ( i = 1; i <= years; i++ ) { futureValue += futureValue * annualRate; }

1100

How many times will the while loop that follows be executed? var months = 5; var i = 1; while (i < months) { futureValue = futureValue * (1 + monthlyInterestRate); i = i+1; }

4

What is the value of salesTax after the following code executes? var salesTax = 53.937; salesTax = parseFloat( salesTax.toFixed(2) );

53.94

What does the following code do? Number.prototype.toCurrencyString = function () { return "$" + this.toFixed(2); }

Creates a method that can be called from a variable that holds an integer or floating-point number.

Cross-browser compatibility is a serious development issue because Internet Explorer and the other browsers don't always interpret

HTML, CSS, and JavaScript the same way

Which of the following is a true statement about objects?

The Number type inherits the methods of the Object type.

Which HTML event occurs when an element on the page loses focus?

blur

Which of the following statements is false? A JavaScript identifier

can start with a number

var add = function( x, y ) { return ( x + y ); } alert( add (5, 3) );

displays a dialog box with a value of "8".

Now that HTML5 is used by all modern browsers, the HTML div element should be used primarily for grouping

elements for JavaScript and jQuery applications

When the statement that follows is executed, JavaScript var rate = parseFloat(document.getElementById("rate").value);

executes the getElementById method, gets the value property of the resulting object, and executes the parseFloat method on that value

Which letter is used to a create a flag for a case-insensitive regular expression?

i

Which operator returns true if an object is the specified object type?

instanceof

When the statement that follows is executed, a message is displayed if the value in userEntry if (!isNaN(userEntry) || userEntry <= 0 ) { alert ("Message"); }

is a number or the value in userEntry is less than or equal to zero

Which keyboard event occurs when a key has been released?

keyup

Which mouse event occurs when the mouse pointer hovers over an HTML element?

mouseover

The order of precedence for arithmetic expressions causes

multiplication operations to be performed before addition operations

A cascading method is one that

returns the object referred to by the this keyword.

A cross-browser compatible method for attaching an event handler must provide parameters for

the HTML node, the event, and the event handler

What method of the Math object can be used to return the largest value from the values that are passed to it?

the Math.max method

To make sure that the ECMAScript 5 features will work in older browsers, you can use

the shim.js file

When you develop a web page, you should use HTML to provide

the structure and content for the page

To load a web page from a local server into your web browser, you can

use the Open or Open File command in the File menu

Which of the following is a valid statement for declaring and initializing a variable named length to a starting value of 120?

var length = 120;

After the if statement that follows is executed, what will the value of discountAmount be? var discountAmount; var orderTotal = 200; if (orderTotal > 200) { discountAmount = orderTotal * .3; } else if (orderTotal > 100) { discountAmount = orderTotal * .2; } else { discountAmount = orderTotal * .1; }

40.0

Which of the following is a true statement about objects?

A variable holds a reference to an object, not the object itself.

Code example 11-2 var percentPrototype = { getPercent: function(subtotal) { var percent = subtotal * this.rate; return percent.toFixed(2); }, format: function(subtotal) { return this.getPercent(subtotal) + "%"; } }; var commissionPrototype = Object.create(percentPrototype); commissionPrototype.getPercent = function(subtotal) { var percent = percentPrototype.getPercent.call(this, subtotal); return (this.isSplit)? percent / 2: percent; }; var commissionCalculator = function(taxRate, isSplit) { var commission = Object.create(commissionPrototype); commission.rate = taxRate; commission.isSplit = isSplit; return commission; }; (Refer to code example 11-2) The commissionPrototype object

is the prototype object for the object returned by the commissionCalculator function

Code example 10-3 var tasks = []; var displayTaskList = function() { // get tasks from storage if (tasks.length === 0) { tasks = getStorage("tasks_10"); } // display sorted tasks with delete links displaySortedTaskList(tasks, $("tasks"), deleteFromTaskList); // set focus on task text box $("task").focus(); }; (Refer to code example 10-3.) This code is from the main JavaScript file for an application. It calls the getStorage function from a storage library and it calls the displaySortedTaskList function from a task list library. As a result, the script elements for the JavaScript libraries must be in this sequence:

it depends upon whether one library calls functions in the other library

After you've coded the constructor for an object type, you can add a method to that object type by adding a function to its

prototype object

Which of the following statements runs the newTimer function every 3 seconds?

setInterval(newTimer, 3000);

What method of the Number object returns a string with the number rounded to the specified number of decimal places?

toFixed method

Which of the following is a valid selector for a class named menu?

.menu

If totalMonths has a string value of "13", what does the if statement that follows display? var years = parseInt ( totalMonths / 12 ); var months = totalMonths % 12; if ( years == 0 ) { alert ( months + " months."); } else if ( months == 0 ) { alert ( years + " years"); } else { alert ( years + " years, and " + months + " months."; }

1 years, and 1 months

What will the value of the totalsString variable be after the following code is executed? var totals = [141.95, 212.95, 411, 10.95]; totals[2] = 312.95; var totalsString = ""; for (var i = 0; i < totals.length; i++) { totalsString += totals[i] + "|"; }

141.95|212.95|312.95|10.95|

ode example 11-1 var invoice = { getSalesTax: function( subtotal ) { return ( subtotal * this.taxRate ); }, getTotal: function ( subtotal, salesTax ) { return subtotal + salesTax; }, taxRate: 0.0875 }; (Refer to code example 11-1.) This code creates an object with

2 methods and 1 property

Assume userName equals "Tom" and userAge equals 22. What is displayed in a dialog box when the following statement is executed? alert(userAge + " \nis " + userName + "'s age.");

22 is Tom's age.

What is the value of random after the following code executes? var random = Math.floor(Math.random() * 10); random = random + 1;

An integer between 1 and 10

Code example 11-3 var Employee = function(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; }; Employee.prototype.getFullName = function() { return this.firstName + " " + this.lastName; }; (Refer to code example 11-3.) The following code displays var employee = new Employee("Grace", "Hopper"); alert (employee.firstName);

Grace

Code example 11-3 var Employee = function(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; }; Employee.prototype.getFullName = function() { return this.firstName + " " + this.lastName; }; (Refer to code example 11-3.) The following code displays var employee = new Employee("Grace", "Hopper"); employee.lastName = "Murach"; alert (employee.getFullName());

Grace Murach

If a numerical operation returns a number greater than the largest possible JavaScript value, it returns

Infinity

What text does the following code display in the dialog box? var investment = "$100"; if (isNaN(investment) || investment <= 0) { alert("Investment is not valid."); } else { alert("Investment: " + investment.toFixed(2)) }

Investment is not valid.

Assume that you have an object of the Object type named employee. Assume also that this object only has two properties named firstName and lastName. What does the following code do? employee.streetAddress = "123 Main Street";

It adds a property named streetAddress to the employee object.

var invoice = { getSalesTax: function( subtotal ) { return ( subtotal * this.taxRate ); }, getTotal: function ( subtotal, salesTax ) { return subtotal + salesTax; }, taxRate: 0.0875 }; (Refer to code example 11-1.) This code creates an object of the

Object type

Which of these statements is true?

The call method passes its parameters as a comma-separated list, while the apply method passes them as an array.

Code example 11-2 var percentPrototype = { getPercent: function(subtotal) { var percent = subtotal * this.rate; return percent.toFixed(2); }, format: function(subtotal) { return this.getPercent(subtotal) + "%"; } }; var commissionPrototype = Object.create(percentPrototype); commissionPrototype.getPercent = function(subtotal) { var percent = percentPrototype.getPercent.call(this, subtotal); return (this.isSplit)? percent / 2: percent; }; var commissionCalculator = function(taxRate, isSplit) { var commission = Object.create(commissionPrototype); commission.rate = taxRate; commission.isSplit = isSplit; return commission; }; (Refer to code example 11-2) Which of the following statements best describes the relationship between the percentPrototype object and the commissionPrototype object?

The commissionPrototype object inherits the methods of the percentPrototype object and overrides its getPercent method.

What text does the following code display in a dialog box? alert("The file is in \"C:\\My Documents\"");

The file is in "C:\My Documents"

Code example 10-3 var tasks = []; var displayTaskList = function() { // get tasks from storage if (tasks.length === 0) { tasks = getStorage("tasks_10"); } // display sorted tasks with delete links displaySortedTaskList(tasks, $("tasks"), deleteFromTaskList); // set focus on task text box $("task").focus(); }; (Refer to code example 10-3.) Which of the following statements can you be sure is true?

The first argument of the displaySortedTaskList function is an array that's retrieved by the getStorage function.

var add = function (val1, val2, val3) { if ( arguments.length < 1 ) return 0; var sum = 0; for ( var i = 0; i < arguments.length; i++) { sum += arguments[i]; } return sum; } (Refer to code example 10-2.) If the function is called with this statement var sum = add(1); what happens?

The function returns 1.

Within a CSS rule set, a rule includes

a property and a value

Code example 10-1 var add = function( x, y ) { return ( x + y ); } alert( add (5, 3) ); (Refer to code example 10-1.) The function

accepts 2 parameters and returns 1 value.

var add = function( x, y ) { return ( x + y ); } alert( add (5, 3) );

accepts 2 parameters and returns 1 value.

When a client requests a dynamic web page, the HTML is generated by

an application server

Three of the common CSS selectors select

by element type, id attribute, and class attribute

Because JavaScript uses lexical scope, you can tell the scope of a variable

by where it is located in the JavaScript code

The class attribute

can be used by CSS to apply the same formatting to more than one HTML element

The easiest way to run a web page that's already in your browser after you've made changes to the code for the page is to

click on the Reload or Refresh button

If you're using Aptana to edit an HTML file, the easiest way to test it is to

click on the Run button in Aptana's toolbar

The following code var display_error = function(message) { alert("Error: " + message); }

creates a function and stores it in a variable named display_error.

Given a Date object named due_date, which of the following statements sets the month to February?

due_date.setMonth(1);

Code example 13-1 var evt = { attach: function(node, eventName, func) { if (node.addEventListener) { node.addEventListener(eventName, func); } else if (node.attachEvent) { node.attachEvent("on" + eventName, func); } }, detach: function(node, eventName, func) { if (node.removeEventListener) { node.removeEventListener(eventName, func); } else if (node.detachEvent) { node.detachEvent("on" + eventName, func); } }, preventDefault: function(e) { e = e || window.event; if ( e.preventDefault ) { e.preventDefault(); } else { e.returnValue = false; } } }; (Refer to code example 13-1.) This is the code for a cross-browser compatible library for working with events. To attach an event handler named toggleH2 to the click event of a heading with "q1" as its id, you code which of the following statements:

e.attach($("q1"),onclick,toggleH2;

Given an event object that's stored in a variable named evt, which of the following statements will cancel the default action in modern browsers?

evt.preventDefault();

Code example 13-1 var evt = { attach: function(node, eventName, func) { if (node.addEventListener) { node.addEventListener(eventName, func); } else if (node.attachEvent) { node.attachEvent("on" + eventName, func); } }, detach: function(node, eventName, func) { if (node.removeEventListener) { node.removeEventListener(eventName, func); } else if (node.detachEvent) { node.detachEvent("on" + eventName, func); } }, preventDefault: function(e) { e = e || window.event; if ( e.preventDefault ) { e.preventDefault(); } else { e.returnValue = false; } } }; (Refer to code example 13-1.) This is the code for a cross-browser compatible library for working with events. In an event handler that uses "event" as the name of the event object that's passed to it, what is the correct code for preventing the default action of a link?

evt.preventDefault(event);

Code example 11-2 var percentPrototype = { getPercent: function(subtotal) { var percent = subtotal * this.rate; return percent.toFixed(2); }, format: function(subtotal) { return this.getPercent(subtotal) + "%"; } }; var commissionPrototype = Object.create(percentPrototype); commissionPrototype.getPercent = function(subtotal) { var percent = percentPrototype.getPercent.call(this, subtotal); return (this.isSplit)? percent / 2: percent; }; var commissionCalculator = function(taxRate, isSplit) { var commission = Object.create(commissionPrototype); commission.rate = taxRate; commission.isSplit = isSplit; return commission; }; (Refer to code example 11-2) The commissionCalculator function is an example of a

factory function

After the statements that follow are executed, var firstName = "Ray", lastName = "Harris"; var fullName = lastName; fullName += ", "; fullName += firstName;

fullName="Harris, Ray"

Which property of an Error object stores the type of error?

name

Which of the following is NOT part of an HTTP URL:

node

If you're using the Chrome browser and a JavaScript application stops running due to an error in the JavaScript code, you can identify the statement that caused the error by

pressing F12 and reviewing the code in the Sources panel

Which of the following statements runs the newTimer function once after 3 seconds?

setTimeout(newTimer, 3000);

Which method of a regular expression searches a string and returns true if the pattern is found?

test

Which of the following statements performs a case-insensitive comparison of the strings named text1 and text2?

text1.toLowerCase() == text2.toLowerCase()

After the statement that follows is executed, rateText represents var rateText = document.getElementById("rate");

the HTML element with "rate" as its id attribute

Code example 13-1 var evt = { attach: function(node, eventName, func) { if (node.addEventListener) { node.addEventListener(eventName, func); } else if (node.attachEvent) { node.attachEvent("on" + eventName, func); } }, detach: function(node, eventName, func) { if (node.removeEventListener) { node.removeEventListener(eventName, func); } else if (node.detachEvent) { node.detachEvent("on" + eventName, func); } }, preventDefault: function(e) { e = e || window.event; if ( e.preventDefault ) { e.preventDefault(); } else { e.returnValue = false; } } }; (Refer to code example 13-1.) This is the code for a cross-browser compatible library for working with events. In the code for the attach method, the if clause provides for modern browsers and the else if clause provides for older IE browsers. This shows that older browsers require the use of

the attachEvent method of a node object and the prefix "on" for the event name

To remove the focus from a control, what method do you use?

the blur method

Code example 13-1 var evt = { attach: function(node, eventName, func) { if (node.addEventListener) { node.addEventListener(eventName, func); } else if (node.attachEvent) { node.attachEvent("on" + eventName, func); } }, detach: function(node, eventName, func) { if (node.removeEventListener) { node.removeEventListener(eventName, func); } else if (node.detachEvent) { node.detachEvent("on" + eventName, func); } }, preventDefault: function(e) { e = e || window.event; if ( e.preventDefault ) { e.preventDefault(); } else { e.returnValue = false; } } }; (Refer to code example 13-1.) This is the code for a cross-browser compatible library for working with events. In the code for the preventDefault method, the first statement sets e equal to either

the event object that's passed to the event handler or the window.event object

What method of the Date object gets the day of the month in local time?

the getDate method

What method of the String object searches the string for an occurence of the specified search string?

the indexOf Method

What method of the String object searches the string for an occurence of the specified search string?

the indexOf method

An HTTP response is sent from

the web server to the client

Which parameters are required when you call the Date constructor with number parameters?

the year and month

Code example 13-1 var evt = { attach: function(node, eventName, func) { if (node.addEventListener) { node.addEventListener(eventName, func); } else if (node.attachEvent) { node.attachEvent("on" + eventName, func); } }, detach: function(node, eventName, func) { if (node.removeEventListener) { node.removeEventListener(eventName, func); } else if (node.detachEvent) { node.detachEvent("on" + eventName, func); } }, preventDefault: function(e) { e = e || window.event; if ( e.preventDefault ) { e.preventDefault(); } else { e.returnValue = false; } } }; (Refer to code example 13-1.) This is the code for a cross-browser compatible library for working with events. It contains

three methods

To load a web page into a web browser, you can

type the URL of the web page into the browser's address bar

Which of the following statements is NOT a valid way to create a date object named birthday?

var birthday = "12/2/1978";

JavaScript code runs on the

web browser


Conjuntos de estudio relacionados

APES Unit 5: Land and Water Use vocab review

View Set

Ch 3 - Cell Structure & Function

View Set

Chapter 7 Supplier Relationship Management

View Set

the fetal face and neck PRACTICE QUIZ

View Set

Chapter 19 Relationship of Principal and Agent

View Set